Bigdata, Hadoop ecosystem, Semantic IoT등의 프로젝트를 진행중에 습득한 내용을 정리하는 곳입니다.
필요한 분을 위해서 공개하고 있습니다.
문의사항은 gooper@gooper.com로 메일을
보내주세요.
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(); } }
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
8 | [JSON 파싱]mongodb의 document를 GSON을 이용하여 parsing할때 ObjectId값에서 오류 발생시 조치방법 | 총관리자 | 2017.01.18 | 327 |
7 | like검색한 결과를 기준으로 집계를 수행하는 java 소스 | 총관리자 | 2016.12.19 | 130 |
6 | MongoDB에 있는 특정컬럼의 값을 casting(string->integer)하여 update하기 java 소스 | 총관리자 | 2016.12.19 | 93 |
5 | mongodb aggregation query를 Java code로 변환한 샘플 | 총관리자 | 2016.12.15 | 777 |
4 | mongodb에서 큰데이타 sort시 오류발생에 대한 해결방법 | 총관리자 | 2015.12.22 | 145 |
» | console명령과 API비교 | 총관리자 | 2015.12.21 | 120 |
2 | SQL문장과 Mongo에서 사용하는 명령어를 비교한 것입니다. | 총관리자 | 2015.09.30 | 141 |
1 | mongodb 2.6.6 설치(64bit) | 총관리자 | 2015.09.30 | 186 |