javascript - Mongodb update() vs. findAndModify() performace -


for constantly growing document, have choice of using either update() or findandmodify() insert new elements in array field. however, findandmodify() generate cleaner code in specific application. can achieve same functionality using update(), more messy.

i'm wondering how performance gain using update() instead of findandmodify(). lot!

i ran quick test using mongo shell. document:

{    "c" : 50,    "growingarray" : [ 0 ] } 

i ran 2 tests:

for (i = 1; < 10000; i++) {     db.testids.update( { "c" : 50 }, { $addtoset : { "growingarray" : } } ); } 

took total of 40.926s on mid-range laptop.

the findandmodify() version:

for (i = 1; < 10000; i++) {     db.testids.findandmodify({ query: { "c" : 50 }, update : { $addtoset : { "growingarray" : } } } ); } 

took 42.445 seconds. averaged 5 runs of each.

take will. knee-jerk conclusion have 3% 4% overhead findandmodify() in particular environment nothing else going on. keep in mind though findandmodify() obtains write locks have greater impact on performance of application overall.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -