我对 MongoDB 和 MongoJack 完全陌生。
我有这个集合叫pbf
{
"_id" : ObjectId("541ea72044ae1b4043e9ccba"),
"name" : "First civ game",
"type" : "WAW",
"numOfPlayers" : 4,
"active" : true,
"players" : [ ],
"civs" : [
{
"objectType" : "civ",
"name" : "Indians",
"used" : false,
"hidden" : true
},
{
"objectType" : "civ",
"name" : "Arabs",
"used" : false,
"hidden" : true
},
{
"objectType" : "civ",
"name" : "Japanese",
"used" : false,
"hidden" : true
},
{
"objectType" : "civ",
"name" : "Egyptians",
"used" : false,
"hidden" : true
},
}
我想做的“按ID删除并返回一个civs项目”
我尝试过这样的事情:
protected static JacksonDBCollection<PBF, String> pbfCollection;
BasicDBObject field = new BasicDBObject();
field.put("civs", 1);
field.put("_id", "541ea72044ae1b4043e9ccba");
PBF pbf = pbfCollection.findAndRemove(field)
但这只是抛出异常说它没有找到任何东西
所以基本上我希望这个返回
{
"objectType" : "civ",
"name" : "Indians",
"used" : false,
"hidden" : true
}
我怎样才能做到这一点?