I have a collection in MongoDB from which I'd like to pull a random sample. This will be about 14,000 documents or so. I'd like every document in this random sample to be updated. What's the best/most efficient way to do this?
Here's the code I have right now, but it's lacking an update
part.
db.collection(collection).aggregate([{ $sample: { size: sample_size } }]).toArray((err, docs) => {
if (err) {
console.log(err);
}
else {
// update all 14,000 (or so) documents that were just pulled
}
})