메뉴 건너뛰기

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

  

번호 제목 날짜 조회 수
190 원격 리포지토리에서 최초 clone시 Permission denied (publickey). 오류발생시 조치사항 2017.06.20 4516
189 resouce manager에 dr.who가 아닌 다른 사용자로 로그인 하기 2018.06.28 4517
188 [Atlas Server]org.apache.hadoop.hbase.security.AccessDeniedException: Insufficient permissions (user=atlas/node01.gooper.com@GOOPER.COM, scope=default:atlas_janus, params=[table=default:atlas_janus,], action-CREATE)] 2023.05.15 4519
187 [CDP7.1.7][Replication]Table does not match version in getMetastore(). Table view original text mismatch 2024.01.02 4519
186 [Active Directory] AD Kerberos보안 설정 변경 방법 (Maximum lifetime for user ticket, Maximum lifetime for user ticket renewal) 2024.03.12 4521
185 avro 사용하기(avsc 스키마 파일 컴파일 방법, consumer, producer샘플소스) 2016.07.08 4522
184 sequence한 번호 생성방법 2014.04.25 4523
183 hadoop 2.6.0에 sqoop2 (1.99.5) server및 client설치 == fail 2015.06.11 4525
182 Oracle NLOB type의 데이터를 import하는 경우 No Java type for SQL type 2011 for column rst와 같은 오류 발생시 조치사항 2022.01.14 4526
181 [CDP7.1.7]Hive Replication수행중 Specified catalog.database.table does not exist : hive.db명.table명 오류 발생시 조치방법 2024.04.05 4526
180 ../depcomp: line 512 exec : g++ : not found 2013.03.08 4527
179 [Hue]Hue의 메타정보를 담고 있는 desktop_document테이블과 desktop_document2의 관계 2022.05.09 4529
178 json serde사용법 2014.04.17 4535
177 [CDP7.1.7]Hive Replication수행시 Target Cluster에서 Specified catalog.database.table does not exist 오류 2024.05.08 4537
176 update 샘플 2018.03.12 4546
175 [CDP7.1.6,HDFS]HDFS파일을 삭제하고 Trash비움이 완료된후에도 HDFS 공간을 차지하고 있는 경우 확인/조치 방법 2023.07.17 4547
174 [sbt] sbt-assembly를 이용하여 실행에 필요한 모든 j라이브러리를 포함한 fat jar파일 만들기 2016.07.11 4556
173 oozie가 말하는 start시간은..서버에서 확인되는 시간이 아닙니다. 2014.05.14 4557
172 [DBeaver 4.3.0]import/export시 "Client home is not specified for connection" 오류발생시 조치사항 2017.12.21 4560
171 "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
위로