I have a collection with 9 million records. I am currently using the following script to update the entire collection:
simple_update.js
db.mydata.find().forEach(function(data) {
db.mydata.update({_id:data._id},{$set:{pid:(2571 - data.Y + (data.X * 2572))}});
});
This is run from the command line as follows:
mongo my_test simple_update.js
So all I am doing is adding a new field pid based upon a simple calculation.
Is there a faster way? This takes a significant amount of time.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…