0
MongoDB에서 processedClickClick 콜렉션이 있습니다.
{
"_id" : ObjectId("58ffb4cefbe21fa7896e2d73"),
"ID" : "81a5d7f48e5df09c9bc006e7cc89d6e6",
"USERID" : "206337611536",
"DATETIME" : "Fri Mar 31 17:29:34 -0400 2017",
"QUERYTEXT" : "Tom",
"DOCID" : "www.demo.com",
"TITLE" : "Harry Potter",
"TAB" : "People-Tab",
"TOTALRESULTS" : "1",
"DOCRANK" : 1
}
{ "id":
....
}
java에서 복잡한 쿼리를 실행하려고합니다.
- TAB가 동일하지 않은 경우 내 쿼리 processedClickLog 수집을 얻을 수 있습니다 사람들 탭
- DOCRANK 0
- 만 반환 "USERID", "DOCID", "DOCRANK", "QUERYTEXT 같지 않은 "
USERID하여 필드
String jsonResult = "";
MongoClient mongoClient = new MongoClient("localhost", 27017);
MongoDatabase database = mongoClient.getDatabase("test1");
MongoCollection<Document> collection = database.getCollection("processedClickLog");
//add condition where TAB is not equal to "People-Tab" and DOCRANK is not equal to 0
List<DBObject> criteria = new ArrayList<DBObject>();
criteria.add(new BasicDBObject("DOCRANK", new BasicDBObject("$ne", 0)));
criteria.add(new BasicDBObject("TAB", new BasicDBObject("$ne", "People-Tab")));
//combine the above two conditions
BasicDBObject query = new BasicDBObject("$and", criteria);
//to retrieve all the documents with specific fields
MongoCursor<Document> cursor = collection.find(query)
.projection(Projections.include("USERID", "DOCID", "DOCRANK", "QUERYTEXT")).iterator();
try {
while (cursor.hasNext()) {
System.out.println(cursor.next().toJson());
}
} finally {
cursor.close();
}
System.out.println(hashMap);
mongoClient.close();
}
Java에서 "group by USERID"조건을 추가하려면 전체 쿼리를 어떻게 정의해야합니까? 어떤 도움을 주신다면
감사합니다. 나는 이것을 시도하고 알려 줄 것입니다. – Rose
매력처럼 작동했습니다. 고마워요 – Rose
그룹 부분에 대해 간단히 설명 할 수 있습니까? 참조 링크에서 그와 관련된 내용을 찾지 못했습니다. – Rose