以下查询在mongo 4.2版上正常运行,但是当我在旧版上运行相同的查询时,这是一个错误-“ ($)
中以美元$concat
为前缀的字段GUID.$concat
对于存储无效”。
db.getCollection('xxxx').update(
{ "SHARE": false },
[{
"$set": {
"GUID": {
"$concat": [
{ $toString: "$ID" },
{ $toString: "$DATE" }
]
}
}
}],
{
upsert: false,
multi: true
}
)
有什么方法可以在较早的mongo版本中修改上述查询。
答案 0 :(得分:0)
下面的查询对我有用,
db.getCollection('xxxx')。aggregate([{$ addFields:{GUID:{$ concat:[{$ toString:“ $ ID”}]}}}])。forEach(function(x){ db.getCollection('xxxx')。update({“ _ id”:x._id},{$ set:{GUID:x.GUID}},{multi:true}); //print((x._id。 toString()))})