BasicDBObject doc = new BasicDBObject(); doc.put("$exists",false); BasicDBObject docs = new BasicDBObject(); docs.put("catalog_id", catalogId); docs.put("isEsbSync_ml",doc); // Bson filter = Filters.eq("catalog_id", catalogId); FindIterable<Document> documents = collection.find(docs); // MongoCursor cursor = findIterable.iterator(); // while (cursor.hasNext()) { // System.out.println("----"+cursor.next()); // } // FindIterable findIterable = collection.find(filter); // MongoCursor cursor = findIterable.iterator(); // while (cursor.hasNext()) { // System.out.println("----"+cursor.next()); // } List<Document> list=new ArrayList<>(); if (documents!=null){ for (Document document : documents) { System.out.println("--document--"+document); list.add(document); } } System.out.println("----->>>"+list.size());
$exists 查询表中是否含有某个字段