mongodb裡的語句:db.getCollection('v1_block_schema').find({$or:[{"user_id":ObjectId("5af52c14e946e423c0824e20")},{$and:[{"is_share":1},{"shareUsers":{$in:["5aceff9e45f51c...
mongodb裡的語句:db.getCollection('v1_block_schema').find({$or:[{"user_id":ObjectId("5af52c14e946e423c0824e20")},{$and:[{"is_share":1},{"shareUsers":{$in:["5aceff9e45f51c1e38414947"]}}]}]})
java裡的語句:
String userId=(String) request.getSession(true).getAttribute("user_id");
Document queryAnd = new Document();
List queryList = new ArrayList();
queryList.add(new Document("is_share",1));
List userIdList = new ArrayList();
userIdList.add(userId);
queryList.add(new Document("shareUsers",new Document("$in",userIdList)));
queryAnd.put("$and",queryList);
List orList = new ArrayList();
Document userDoc = new Document();
userDoc.put("user_id",new ObjectId(userId));
if(keyword != null && keyword !=""){
Document doc = new Document();
List docList = new ArrayList();
docList.add(new Document("user_id",new ObjectId(userId)));
docList.add(new Document("name",new Document("$regex",keyword)));
doc.put("$and",docList);
userDoc = doc;
}
orList.add(userDoc);
orList.add(queryAnd);
Document queryOr = new Document();
queryOr.put("$or",orList);
Page page = mongoDbStore.queryPages("v1_block_schema",queryOr,new Document(),skip,20);
怎麼可以像jdbc那樣寫一串string字元串資料庫就可以識别成mongodb的語句了
展開