gpt4 book ai didi

mysql - Mongo更新查询相当于mysql中

转载 作者:行者123 更新时间:2023-11-29 18:04:47 26 4
gpt4 key购买 nike

我正在尝试更新 mongodb 中的多条记录。单条记录如下:

"_id" : ObjectId("59704fac4ed2aa47e68c7f50"),
"uid" : 157140,
"ts" : NumberLong("170720120636"),
"a" : {
"em" : "email20788@pragatee.com",
"fk" : "email20788@pragatee.com",
"mo" : "1248849893",
"d" : 0,
"bl" : 0,
"att3" : "city20788",
"att66" : "fname20788"
}
}
{
"_id" : ObjectId("59704fac4ed2aa47e68c7f51"),
"uid" : 157141,
"ts" : NumberLong("170720120636"),
"a" : {
"em" : "email20789@pragatee.com",
"fk" : "email20789@pragatee.com",
"mo" : "1248849920",
"d" : 0,
"bl" : 0,
"att3" : "city20789",
"att66" : "fname20789"
}
}

我想更新某些记录的数组“a.d”的值。

我正在尝试的查询:

db.userDetails.find({ uid : {$in : [157140,157141]}}).update({$set: {"a.d":1}})

但我收到错误:

"errmsg" : "A single update on a sharded collection must contain an exact match on _id (and have the collection default collation) or contain the shard key (and have the simple collation). Update request: { q: { uid: { $in: [ 157140.0, 157141.0 ] } }, u: { $set: { a.d: 1.0 } }, multi: false, upsert: false }, shard key pattern: { uid: 1 }"

最佳答案

db.collection.find().forEach( function(doc) {
do {
db.collection.update({_id: doc._id,{$elemMatch_{user__test_,{$ne:"new_avatar.jpg"}}}},{$set:{"comments.$.avatar":"new_avatar.jpg"}});
} while (db.getPrevError().n != 0);
})

关于mysql - Mongo更新查询相当于mysql中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47976365/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com