메뉴 건너뛰기

Cloudera, BigData, Semantic IoT, Hadoop, NoSQL

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


mongodb console명령과 API비교

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

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

  

번호 제목 날짜 조회 수
120 "Initial job has not accepted any resources; check your cluster UI to ensure that workers are registered and have sufficient resources"오류 발생시 조치사항 2016.05.25 1143
119 spark-env.sh에서 사용할 수있는 항목. 2016.05.24 870
118 Spark 1.6.1 설치후 HA구성 2016.05.24 741
117 spark-shell실행시 "A read-only user or a user in a read-only database is not permitted to disable read-only mode on a connection."오류가 발생하는 경우 해결방법 2016.05.20 635
116 Master rejected startup because clock is out of sync 오류 해결방법 2016.05.03 159
115 kafka broker기동시 brokerId가 달라서 기동에 실패하는 경우 조치방법 2016.05.02 2424
114 kafka 0.9.0.1 for scala 2.1.1 설치및 테스트 2016.05.02 592
113 Spark 2.1.1 clustering(5대) 설치(YARN기반) 2016.04.22 2071
112 Hadoop 완벽 가이드 정리된 링크 2016.04.19 458
111 bin/cassandra -f -R로 startup할때 NullPointerException오류가 나면 조치할 내용 2016.04.14 249
110 Cassandra 3.4(3.10) 설치/설정 (5대로 clustering) 2016.04.11 656
109 Incompatible clusterIDs오류 원인및 해결방법 2016.04.01 580
108 namenode오류 복구시 사용하는 명령 2016.04.01 503
107 "java.net.NoRouteToHostException: 호스트로 갈 루트가 없음" 오류시 확인및 조치할 사항 2016.04.01 3229
106 CentOS의 서버 5대에 yarn(hadoop 2.7.2)설치하기-ResourceManager HA/HDFS HA포함, JobHistory포함 2016.03.29 1203
105 Spark Streaming으로 유실 없는 스트림 처리 인프라 구축하기 2016.03.11 270
104 CDH 5.4.4 버전에서 hive on tez (0.7.0)설치하기 2016.01.14 308
103 mongodb에서 큰데이타 sort시 오류발생에 대한 해결방법 2015.12.22 535
» console명령과 API비교 2015.12.21 545
101 DB별 JDBC 드라이버 2015.10.02 495
위로