메뉴 건너뛰기

Cloudera, BigData, Semantic IoT, Hadoop, NoSQL

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


mongodb console명령과 API비교

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

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 sparql 문법구조 설명 file 2015.12.09 3335
189 [kerberos]Kerberos HA구성 참고 페이지 2022.08.31 3324
188 magento2 log파일 위치 2017.01.31 3322
187 nc -l 7777 : 7777포트에서 입력을 받는다. 2017.03.23 3320
186 oozie job 구동시 JA009: User: hadoop is not allowed to impersonate hadoop 오류나는 경우 2014.06.02 3305
185 ./spark-sql 실행시 "java.lang.NumberFormatException: For input string: "1s"오류발생시 조치사항 2016.06.09 3303
184 php auction 프로그램 2017.05.14 3297
183 github에 있는 프로젝트와 로컬에서 작업한 프로젝트 합치기 2016.11.22 3297
182 Cleaning up the staging area file시 'cannot access' 혹은 'Directory is not writable' 발생시 조치사항 2017.05.02 3292
181 Java 8에서 pom.xml에 JavaDoc 관련 태그가 설정되어 있으나 오류등으로 실패하면 나머지 Maven작업이 종료되는 문제 해결 방법 2017.01.24 3292
180 Could not compute split, block input-0-1517397051800 not found형태의 오류가 발생시 조치방법 2018.02.01 3290
179 solrcloud에 solrdf1.1설치하고 테스트 하기 2016.04.22 3286
178 JAVA_HOME을 명시적으로 지정하는 방법 2018.06.04 3285
177 hadoop 기반 문서 검색 2014.09.25 3284
176 bin/cassandra -f -R로 startup할때 NullPointerException오류가 나면 조치할 내용 2016.04.14 3283
175 impala,hive및 hdfs만 접근가능하고 파일을 이용한 테이블생성가능하도록 hue 권한설정설정 2018.09.17 3274
174 RDF4J의 RESTFul API처리 클래스 소스 파악(web module위주) 2017.08.30 3262
173 [SBT] SBT 사용법 정리(링크) 2016.08.04 3262
172 pom.xml에서 build.gradle로 변환 2015.09.14 3261
171 spark2.0.0에서 hive 2.0.1 table을 읽어 출력하는 예제 소스(HiveContext, SparkSession, SQLContext) 2017.03.09 3255
위로