Some sub documents in my collection are missing _ids. I've written this piece of mongo-shell code to try to add them.
db.jobs.updateMany({},
{
$set: {
"artifacts.$[elem]._id": new ObjectId()
}
},
{
arrayFilters: [
{
"elem._id": {
$exists: false
}
}
]
})
This code succeeds in giving all the appropriate subdocuments _ids but it gives them all the same id. Any ideas on how to make the ids unique?