메뉴 건너뛰기

Cloudera, BigData, Semantic IoT, Hadoop, NoSQL

Cloudera CDH/CDP 및 Hadoop EcoSystem, Semantic IoT등의 개발/운영 기술을 정리합니다. gooper@gooper.com로 문의 주세요.


mongodb console명령과 API비교

총관리자 2015.12.21 15:11 조회 수 : 4731

1. 날짜 범위와 문자열의 일부를 이용하여 data를 가져오는 경우

  가. console

    db.getCollection('resource').find({ct:{$gte:"20151221T135154", $lt:"20151221T135236"}}, {_uri:/status/Data/}).count()

  나. Java Api

String m = "status/Data";

MongoClient mongoClient = new MongoClient(new ServerAddress(ip, port));
DB db = mongoClient.getDB(dbname);

BasicDBObject searchQuery = new BasicDBObject("ct",
		new BasicDBObject("$gte", startDate).append("$lt", endDate));
searchQuery.put("_uri", java.util.regex.Pattern.compile(m));

DBCursor cursor = null;
int cnt = 0;

try {
	cursor = table.find(searchQuery);

	while (cursor.hasNext()) {
		DBObject doc = cursor.next();
		log.debug("value of [" + cnt++ + "]...." + doc.toString());

	}
} catch (MongoException e) {
	e.printStackTrace();
	if (db != null) {
		db.cleanCursors(true);
		table = null;
		db = null;
	}
	if (mongoClient != null) {
		mongoClient.close();
	}
	throw e;
} catch (Exception e) {
	e.printStackTrace();
	if (db != null) {
		db.cleanCursors(true);
		table = null;
		db = null;
	}
	if (mongoClient != null) {
		mongoClient.close();
	}
	throw e;
} finally {
	if (cursor != null) {
		cursor.close();
	}
}

  

번호 제목 날짜 조회 수
170 로컬의 라이브러리파일들을 dependency에 포함시키는 방법 2016.08.09 3254
169 hadoop클러스터를 구성하던 서버중 HA를 담당하는 서버의 hostname등이 변경되어 문제가 발생했을때 조치사항 2016.07.29 3254
168 [hive] hive.tbls테이블의 owner컬럼값은 hadoop.security.auth_to_local에 의해서 filtering된다. 2022.04.14 3252
167 Elastic Search For Hadoop 2.2.0설치하기(5대 클러스터링) 2016.04.04 3243
166 [shell script]test.txt에 space로 분리된 내용을 일어들이는 예제 2017.02.21 3241
165 [Elephas] Jena Elephas를 이용하여 Spark에서 rdfTriples의 RDD를 만들고 RDD관련 작업하는 샘플소스 2016.08.10 3239
164 ubuntu 커널 업그레이드 방법 2018.09.02 3224
163 [CentOS] 네트워크 설정 2018.03.26 3217
162 oneM2M Specification(Draft Release 3, 2, 1), Draft Technical Reports 2017.10.25 3217
161 [springframework]Caused by: org.mariadb.jdbc.internal.util.dao.QueryException: Could not read resultset: unexpected end of stream, read 0 bytes from 4 오류 발생시 조치사항 2017.01.23 3215
160 [Mybatis]Spring과 연동하지 않고 Java+Mybatis 형태의 프로그램 샘플소스 2016.09.01 3213
159 외부 기기(usb, 하드)등 mount(연결)하기 2014.08.03 3212
158 Hue Job Browser의 Queries탭에서 조건을 지정하는 방법 2018.05.10 3207
157 centos에 sbt 0.13.5 설치 2016.05.30 3202
156 gradle을 이용하여 jar파일 생성시 provided속성을 지정할 수 있게 설정하는 방법 2016.08.09 3199
155 tar를 이용한 리눅스 백업 2018.05.13 3195
154 select와 group by결과 값이 없는경우의 리턴 값이 다름 file 2016.02.05 3180
153 ./hadoop-daemon.sh start namenode로 namenode기동시 EditLog의 custerId, namespaceId가 달라서 발생하는 오류 해결방법 2016.09.24 3172
152 HBase 설정 최적화하기(VCNC) file 2017.07.18 3167
151 HDFS Balancer설정및 수행 2018.03.21 3166
위로