根据条件删除嵌套文档中某个文档
DBObject queryObject = new BasicDBObject();
queryObject.put("question","帮得佳净亮洗洁精(浓缩型)及补充装多少钱");
DBObject innerDbObject = new BasicDBObject();
innerDbObject.put("title", "302 Found");
BasicDBObject updateObject = new BasicDBObject().append("$pull", new BasicDBObject().append("similarList",innerDbObject));
WriteResult result = baiduCollection.updateMulti(queryObject, updateObject);
模糊查询
Pattern pattern = Pattern.compile("^.*" + "404"+ ".*$", Pattern.CASE_INSENSITIVE);
DBObject queryObject = new BasicDBObject();
queryObject.put("similarList.title", pattern);
DBCursor cursor = baiduCollection.find(queryObject).limit(10);
while (cursor.hasNext()) {
DBObject dbObject = cursor.next();
System.out.println(dbObject);
}
模糊更新子文档
Pattern pattern = Pattern.compile("^.*" + "Suspended Domain"+ ".*$", Pattern.CASE_INSENSITIVE);//404 403 302
DBObject queryObject = new BasicDBObject();
DBObject innerDbObject = new BasicDBObject();
innerDbObject.put("title", pattern);
BasicDBObject updateObject = new BasicDBObject().append("$pull", new BasicDBObject().append("similarList",innerDbObject));
WriteResult result = baiduCollection.updateMulti(queryObject, updateObject);
System.out.println(result);