我有成千上万的这种格式的文档:
{
"_id" : ObjectId("51e98d196b01c2085c72d731"),
"messages" : [
{
"_id" : ObjectId("520167056b01c20bb9eee987"),
"id" : ObjectId("520167056b01c20bb9eee987"),
},
{
"_id" : ObjectId("520167056b01c20bb9eee988"),
"id" : ObjectId("520167056b01c20bb9eee988"),
},
{
"_id" : ObjectId("520167056b01c20bb9eee989"),
"id" : ObjectId("520167056b01c20bb9eee989"),
}
],
}
我需要删除重复的“id”字段。这是我尝试过的:
db.forum_threads.update({}, {$unset: {"messages.$.id": 1}}, {multi: true});
这是我得到的错误:
Cannot apply the positional operator without a corresponding query field containing an array.