메뉴 건너뛰기

Cloudera, BigData, Semantic IoT, Hadoop, NoSQL

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


mongodb console명령과 API비교

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

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();
	}
}

  

번호 제목 날짜 조회 수
230 Collections.sort를 이용한 List<Map<String, String>>형태의 데이타 정렬 소스 2016.12.15 3471
229 mybais #과 $의 차이점 2015.11.10 3465
228 Spark Streaming으로 유실 없는 스트림 처리 인프라 구축하기 2016.03.11 3462
227 How-to: Tune Your Apache Spark Jobs (Part 2) file 2016.10.31 3457
226 sendmail + dovecot(pop3) + saslauthd 설치 2017.06.11 3453
225 oracle 접속 방식에 따른 --connect 지정 방법 2022.02.11 3452
224 compile할때와 exclude할때 대상을 표현하는 명칭이 다르므로 주의할것 2016.08.10 3451
223 collection생성혹은 collection조회시 Plugin init failure for [schema.xml] fieldType "pdate": Error loading class 'solr.IntField' 오류 조치사항 2022.04.07 3440
222 oozie 에서 sqoop action실행 에러 - 컬럼개수 차이 2014.07.17 3440
221 schema.xml vs managed-schema 지정 사용하기 - 두개를 동시에 사용할 수는 없음 2017.07.09 3436
220 Components of the Impala Server 2018.03.21 3433
219 Caused by: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D오류발생시 조치사항 2016.06.03 3429
218 2개 data를 join하고 마지막으로 code정보를 join하여 결과를 얻는 mr 프로그램 2014.06.30 3425
217 solr명령 실행시 "Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect" 오류발생 2017.06.30 3417
216 참고할만한 spark예제를 설명하는 사이트 2016.11.11 3411
215 부팅을 외장하드에서 하도록 변경하는 방법 2015.07.28 3410
214 /etc/logrotate.d 을 이용한 catalina.out 나누기 file 2017.01.19 3409
213 Permission denied: user=hadoop, access=EXECUTE, inode="/tmp":root:supergroup:drwxrwx--- 오류해결방법 2015.05.17 3409
212 동시에 많은 요청이 endpoint로 몰려서java.net.NoRouteToHostException가 발생하는 경우의 처리방법 2016.10.17 3408
211 [Oracle 11g]Kudu table의 meta정보를 담고 있는 table_params의 백업본을 이용하여 특정 컬럼값을 update하는 Oracle SQL문 2023.09.04 3393
위로