根據條件刪除嵌套文檔中某個文檔 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);