我在可能是最基本的事情上遇到了很大的困难。我的数据库中有以下条目
{"_id"=>BSON::ObjectId('4ec2429c85aab65f16fa2700'),
"owner"=>4,
"friends"=>{"mappings"=>{"Test"=>34}},
"friendid"=>"309"}
我正在尝试将另一个值插入到映射数组中。像“测试”=> 10
不幸的是,在尝试各种不同的方法时,我没有任何运气。目前我正在尝试以下但没有成功。
BasicDBObject updateQuery = new BasicDBObject();
updateQuery.put("owner", owner);
updateQuery.put("friendid", userid);
BasicDBObject updateCommand = new BasicDBObject();
updateCommand.put("$push", new BasicDBObject("friends.mappings",
new BasicDBObject(clustername, clusterid)));
WriteResult result = collection.update(updateQuery, updateCommand,false,true);
如果有人能告诉我我做错了什么,我将不胜感激。我假设它的东西非常明显!
Ps 我正在使用最新的驱动程序和最新的 MongoDB