Slow Performance using forEach
Answered
When I run a script like this:
db.collection.find().forEach((it)=> {
db.collection.update({_id: it._id,{$set: {anyfield: "newvalue"}});
});
It runs very slow on nosqlbooster, I think that it's because it's running locally and showing every record that is updated, it normally return:
Updated 1 existing record(s) in 729ms
Updated 1 existing record(s) in 548ms
Updated 1 existing record(s) in 306ms
Updated 1 existing record(s) in 294ms
Updated 1 existing record(s) in 323ms
...
I wanna to disable these logs for this kind of command so it can run very fast, I tried disable: "Options -> Options That May Affect Performance -> Enable Mongo Script Logger", but it doesn't disable.
Ps. I'm running a remote database through a SSH tunnel.
You can call MongoShell method "setVerboseShell(false)" to deactivate the verbose shell.
More about setVerboseShell: https://docs.mongodb.com/manual/reference/method/setVerboseShell/
You can call MongoShell method "setVerboseShell(false)" to deactivate the verbose shell.
More about setVerboseShell: https://docs.mongodb.com/manual/reference/method/setVerboseShell/
The option works well, but it still take a long time to run the same command in NoSQLBooster compared to run directly in mongo shell.
The option works well, but it still take a long time to run the same command in NoSQLBooster compared to run directly in mongo shell.
I tested it, and there were some performance gaps, but within the same order of magnitude (150M records), I believe the performance gap is on mongodb's driver. How many pieces of data do you have to update, and I think that it's not appropriate to update big data one by one with forEach like this.
I tested it, and there were some performance gaps, but within the same order of magnitude (150M records), I believe the performance gap is on mongodb's driver. How many pieces of data do you have to update, and I think that it's not appropriate to update big data one by one with forEach like this.
Replies have been locked on this page!