Hi Chris,
I have a script that updates a few fields in one collection with values pulled from another collection
Is this a script in [mongo shell|https://docs.mongodb.com/manual/mongo/] or using a certain driver?
Could you provide more information about:
mongod process?causes either a timeout
Are there errors or performance related messages in mongod logs. E.g. network errors, slow queries, etc…
or it chokes applications using mongodb
Is the impact only on applications using mongodb or any applications running on that machine in particular? I.e. Is the machine is reaching it’s resource limits when you script is running?
Have you tried using the profiler or mplotqueries to analyze your operations?
Regards,
Amar
Hi Chris,
Looking at the code provided, remove() is given the whole document rather than _id which is less efficient. This could look like this:
db.UserSettings.remove( { _id : currentUserSetting._id } )
Note that since the script uses find() with no constraints, it may need to fetch the whole collection into memory. This may be disruptive to your working set and may contribute to the performance issue you are seeing. For more information, please see Must my working set size fit RAM. Additional things that you can look at are:
mongod?mongod logs that may point to resource issues (e.g. slow queries, etc)Regarding performance issues, these links may be of interest to you:
Regards,
Amar