I have a users collection with a likes array. I need to update all of the likes for every user.
I wrote a script to do that, but it is crazy slow. I need to update tens of millions of users.
db.users.find().forEach( function(user) {
users.likes.forEach( function(like){
like.stars = 5;
});
db.users.save(user);
});
Do you know any faster way to achieve this?
EDIT:
A sample document would look like:
{
"_id" : ObjectId("4f0f31ab0c20020600012301"),
"created_at" : ISODate("2012-01-12T19:16:59.748Z"),
"predictions" : null,
"likes" : [
{
"_id" : ObjectId("4f0f4a3978c7890600020f2b"),
"brand_id" : "bcbgmaxazria"
}
],
"updated_at" : ISODate("2012-12-19T10:09:20.000Z")
}
I want to add a new stars field with the value 5 to all of the objects in the likes collections.