메뉴 건너뛰기

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

  

번호 제목 날짜 조회 수
270 [번역] solr 검색 엔진 튜토리얼 2014.10.07 3633
269 hive기동시 Caused by: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D 오류 발생시 조치사항 2016.09.25 3631
268 jena/fuseki 3.4.0 설치 2017.07.25 3630
267 federated query 예제 2017.01.19 3627
266 crypto관련 기생충 박멸 스크립트 2018.05.11 3626
265 producer / consumer구현시 설정 옵션 설명 2016.10.19 3621
264 원격의 origin/master를 기준으로 dev branch를 만들어 작업후 원격의 origin/dev에 push하는 방법 file 2016.11.22 3616
263 프로그래밍 언어별 딥러닝 라이브러리 정리 file 2016.10.05 3615
262 python3.5에서 numpy버젼에 따른 문제점을 조치하는 방법및 pymysql import할때 오류 발생시 조치사항 2017.09.28 3614
261 jena jar파일실행시 org.apache.jena.tdb.TDB.init에서 java.lang.NullPointerException발생시 조치사항 2016.08.19 3611
260 Embedded PostgreSql설정을 외부의 MariaDB로변경하기 [1] 2018.05.22 3607
259 update를 많이 하면 heap memory가 많이 소진되고 최종적으로 OOM가 발생하는데 이에 대한 설명 2017.04.10 3607
258 git 초기화(Windows에서 Git Bash사용) 2016.11.17 3607
257 이미지 관리 오픈소스 목록 2018.03.11 3601
256 maven을 이용하여 Hello world 서비스 자동 생성시 HelloServiceImpl.java에서 사용하는 getMessage() 와 getName() 이 정의되지 않은 오류가 발생시 조치방법 2018.01.19 3599
255 RDF4J의 rdf4j-server.war가 제공하는 RESTFul API를 이용하여 repository에 CRUD테스트 2017.08.30 3592
254 hive에서 insert overwrite directory.. 로 하면 default column구분자는 'SOH'혹은 't'가 됨 2014.05.20 3590
253 CDH 5.14.2 설치중 agent설치에서 실패하는 경우 확인/조치 2018.05.22 3576
252 spark notebook 0.7.0설치및 설정 2016.11.14 3574
251 spark submit용 jar파일을 만드는 sbt 용 build.sbt설정 파일(참고용) 2016.08.19 3561
위로