使用命令将文档中的值复制到mongodb中的另一个文档中

使用命令将文档中的值复制到mongodb中的另一个文档中,mongodb,mongodb-query,Mongodb,Mongodb Query,如何在同一集合中复制文档键的值 例如: 从下面的文档到 { "_id" : "werty4567tfdxc6ytf", "thumbnail" : "somelargebase64encodedstring", "other1" : "value" } { "_id" : "sdf4567g67h8njomioh" // thumbna

如何在同一集合中复制文档键的值

例如: 从下面的文档到

{
"_id" : "werty4567tfdxc6ytf",
"thumbnail" : "somelargebase64encodedstring",
"other1" : "value"
}

{
"_id" : "sdf4567g67h8njomioh"
// thumbnail in the above document need to go here
"other2": "value" // these values shouldnt be replaced by above doc values
}
使用$merge

MongoDB Enterprise > db.t.insert({ "_id" : "werty4567tfdxc6ytf", "thumbnail" : "somelargebase64encodedstring" })
WriteResult({ "nInserted" : 1 })

MongoDB Enterprise > db.t.aggregate([{$set:{_id:'sdf4567g67h8njomioh'}}])
{ "_id" : "sdf4567g67h8njomioh", "thumbnail" : "somelargebase64encodedstring" }

MongoDB Enterprise > db.t.aggregate([{$set:{_id:'sdf4567g67h8njomioh'}},{$merge:'t'}])

MongoDB Enterprise > db.t.find()
{ "_id" : "werty4567tfdxc6ytf", "thumbnail" : "somelargebase64encodedstring" }
{ "_id" : "sdf4567g67h8njomioh", "thumbnail" : "somelargebase64encodedstring" }

谢谢,但是当输出集合与聚合集合相同时,它抛出以下错误$merge不受支持“,而且,我不想对第二条记录做任何更改,除了拇指尾。请考虑我编辑过的问题。我给你的例子用了同样的阅读和写作。使用$set设置所需的任何其他字段。