从阵列中的条目我喜欢JSON:删除使用MongoDB的-Java驱动程序
{
"_id" : "1",
"_class" : "com.model.Test",
"itemList" : [
{
"itemID" : "1",
"itemName" : "Foo",
"resources" : [
{
"resourceID" : "1",
"resourceName" : "Foo Test1"
}, {
"resourceID" : "2",
"resourceName" : "Foo Test2"
}
]
}
]
}
我需要能够删除的itemList中的记录之一。 我也做了以下内容:
public void removeItemByID(String docID, String itemID) throws Exception {
MongoOperations mongoOperations = mongoConfiguration.getMongoTemplate();
Query query = new Query(where("_id").is(docID).and("itemList.itemID").is(itemID));
mongoOperations.remove(query, Item.class);
}
这种方法是行不通的。 但是,当我用$ pull方法使用BasicDBObject时,它工作正常! 这些方法有什么区别!
使用Bson是类似的。我把一个[答案在这里](http://stackoverflow.com/a/37846203/1978082) – HenioJR 2016-06-15 21:39:12