我需要在使用mongodb驱动程序的java中使用此请求
db.product.update({"orders._id":ObjectId("59328d583c5179156cb9c241")},
{
$set:{
"orders.$.description":"ccc"
}
})
我的对象
{
"_id" : ObjectId("59328d543c5179156cb9c240"),
"fullName" : "aaa",
"orders" : [
{
"_id" : ObjectId("59328d583c5179156cb9c241"),
"description" : "bbb"
}
]
}
结果
{ " _id" :ObjectId(" 59328d543c5179156cb9c240"), "全名" :" aaa", "命令" :[ { " _id" :ObjectId(" 59328d583c5179156cb9c241"), "描述" :" ccc" } ]}
我尝试了什么
BasicDBObject set = new BasicDBObject("$set", new BasicDBObject("orders._id", myId));
set.append("$set", new BasicDBObject("description", "ccc");
product.update(searchQueryByOrderId, set);
使用的驱动程序: https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver