0
我在使用MongoDB中的_id刪除文檔時遇到了一些問題。我可以通過其他屬性刪除沒有問題,但我似乎缺少用_id刪除正確的語法。如何使用Java在MongoDB 3.3中使用_id刪除文檔
我的文檔格式如下:
{ "_id" : { "$oid" : "57a49c6c33b10927ff09623e" }, "name" : "Brad" }
這裏是我使用的Java代碼:
// Boiler plate
MongoClient client = new MongoClient("localhost" , 27017);
MongoDatabase db = client.getDatabase("my-database");
MongoCollection<Document> collection = db.getCollection("my-collection")
// This works
collection.deleteOne(new Document("name", "Brad"));
// This does not work
collection.deleteOne(new Document("_id", "57a49c6c33b10927ff09623e"));
任何人有在那裏我錯了什麼想法?
萬分感謝,工程巨大。 –