无法使用Mongodb Java驱动程序更新内部Arraylist对象 [英] Unable to update Inner Arraylist object using Mongodb Java Driver
本文介绍了无法使用Mongodb Java驱动程序更新内部Arraylist对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在mongodb数据库中具有以下文档结构:
I have below document structure in mongodb database:
{
"_id" : ObjectId("52ec7b43e4b048cd48499b35"),
"eidlist" : [
{
"eid" : "64286",
"dst" : NumberLong(21044),
"score" : 0
},
{
"eid" : "65077",
"dst" : NumberLong(21044),
"score" : 0
}
],
"src" : NumberLong(21047)
}
我想使用Java-mongodb驱动程序更新第一个对象的得分字段: 我尝试了以下代码,但它不起作用:(:
I would like to update score field of first object using Java-mongodb driver: I tried following code but it is not working :( :
DBObject update_query=new BasicDBObject("src", key).append("eidlist.eid", e.getEdgeid());
DBObject data=new BasicDBObject("$set",new BasicDBObject("eidlist.score",100));
coll.update(update_query, data);
请帮助我解决这个问题..我已经检查了传递给更新函数的所有参数.我认为更新逻辑有问题:(
Please help me to solve this problem..I have checked all the parameter which I have passed to update function.I think something wrong with the update logic :(
推荐答案
您已经关闭.您从更新中省略了位置运算符.如图所示编辑代码.
You were close. You omiited the positional operator from the update. Edit your code as shown.
DBObject data=new BasicDBObject("$set",new BasicDBObject("eidlist.$.score",100));
这篇关于无法使用Mongodb Java驱动程序更新内部Arraylist对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文