메뉴 건너뛰기

Cloudera, BigData, Semantic IoT, Hadoop, NoSQL

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


mongodb console명령과 API비교

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

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

  

번호 제목 날짜 조회 수
111 bin/cassandra -f -R로 startup할때 NullPointerException오류가 나면 조치할 내용 2016.04.14 5760
110 Cassandra 3.4(3.10) 설치/설정 (5대로 clustering) 2016.04.11 4565
109 Incompatible clusterIDs오류 원인및 해결방법 2016.04.01 3052
108 namenode오류 복구시 사용하는 명령 2016.04.01 2951
107 "java.net.NoRouteToHostException: 호스트로 갈 루트가 없음" 오류시 확인및 조치할 사항 2016.04.01 5969
106 CentOS의 서버 5대에 yarn(hadoop 2.7.2)설치하기-ResourceManager HA/HDFS HA포함, JobHistory포함 2016.03.29 4811
105 Spark Streaming으로 유실 없는 스트림 처리 인프라 구축하기 2016.03.11 3614
104 CDH 5.4.4 버전에서 hive on tez (0.7.0)설치하기 2016.01.14 3499
103 mongodb에서 큰데이타 sort시 오류발생에 대한 해결방법 2015.12.22 5117
» console명령과 API비교 2015.12.21 4834
101 DB별 JDBC 드라이버 2015.10.02 4348
100 root계정으로 MariaDB설치후 mysql -u root -p로 db에 접근하여 바로 해줘야 하는일..(케릭터셑은 utf8) 2015.10.02 3903
99 SQL문장과 Mongo에서 사용하는 명령어를 비교한 것입니다. 2015.09.30 4224
98 mongodb 2.6.6 설치(64bit) 2015.09.30 2724
97 Tracking URL = N/A 가발생하는 경우 - 환경설정값을 잘못설정하는 경우에 발생함 2015.06.17 4760
96 java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error: Unable to deserialize reduce input key from...오류해결방법 2015.06.16 6400
95 hortonworks에서 제공하는 메모리 설정값 계산기 사용법 file 2015.06.14 4354
94 Exception in thread "main" java.lang.NoSuchMethodError: org.apache.hadoop.http.HttpConfig.getSchemePrefix()Ljava/lang/String; 해결->실패 2015.06.14 2740
93 hadoop 2.6.0에 sqoop2 (1.99.5) server및 client설치 == fail 2015.06.11 5180
92 "File /user/hadoop/share/lib does not exist" 오류 해결방법 2015.06.07 4558
위로