메뉴 건너뛰기

Cloudera, BigData, Semantic IoT, Hadoop, NoSQL

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


mongodb console명령과 API비교

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

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

  

번호 제목 날짜 조회 수
127 impala 설치/설정 2016.06.03 4505
126 hive 2.0.1 설치및 mariadb로 metastore 설정 2016.06.03 9020
125 Scala버젼 변경 혹은 상황에 맞게 Spark소스 컴파일하기 2016.05.31 4005
124 Job이 끝난 log을 볼수 있도록 설정하기 2016.05.30 4415
123 spark client프로그램 기동시 "Error initializing SparkContext"오류 발생할때 조치사항 2016.05.27 4551
122 spark-submit으로 spark application실행하는 다양한 방법 2016.05.25 4406
121 spark 온라인 책자링크 (제목 : mastering-apache-spark) 2016.05.25 4248
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 4562
119 spark-env.sh에서 사용할 수있는 항목. 2016.05.24 4275
118 Spark 1.6.1 설치후 HA구성 2016.05.24 4439
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 2953
116 Master rejected startup because clock is out of sync 오류 해결방법 2016.05.03 5067
115 kafka broker기동시 brokerId가 달라서 기동에 실패하는 경우 조치방법 2016.05.02 5188
114 kafka 0.9.0.1 for scala 2.1.1 설치및 테스트 2016.05.02 4051
113 Spark 2.1.1 clustering(5대) 설치(YARN기반) 2016.04.22 4957
112 Hadoop 완벽 가이드 정리된 링크 2016.04.19 3655
111 bin/cassandra -f -R로 startup할때 NullPointerException오류가 나면 조치할 내용 2016.04.14 3273
110 Cassandra 3.4(3.10) 설치/설정 (5대로 clustering) 2016.04.11 4342
109 Incompatible clusterIDs오류 원인및 해결방법 2016.04.01 2948
108 namenode오류 복구시 사용하는 명령 2016.04.01 2851
위로