I have thousands of documents in this format:
{
"_id" : ObjectId("51e98d196b01c2085c72d731"),
"messages" : [
{
"_id" : ObjectId("520167056b01c20bb9eee987"),
"id" : ObjectId("520167056b01c20bb9eee987"),
},
{
"_id" : ObjectId("520167056b01c20bb9eee988"),
"id" : ObjectId("520167056b01c20bb9eee988"),
},
{
"_id" : ObjectId("520167056b01c20bb9eee989"),
"id" : ObjectId("520167056b01c20bb9eee989"),
}
],
}
I need to remove the duplicate "id" field. This is what I have tried:
db.forum_threads.update({}, {$unset: {"messages.$.id": 1}}, {multi: true});
This is the error I am getting:
Cannot apply the positional operator without a corresponding query field containing an array.