In the
MongoDB nosql-base there is an analogue of the mysql
INSERT ... ON DUPLICATE KEY UPDATE - upsert (UPdate or inSERT).
How fast does mongodb do it?
The question is not idle, since upsets carry out two operations — read and write. The presence of indexes speeds up reading, but slows down writing. Which of them accelerates more strongly, and who slows down steeper?
')
upd:
Focusing on UPdate
results

Comments
I considered the case when the document has an array and there is an active record. Example - blog comments:
db.blog.insert ({
title: "new post",
content: "<p> Hello world! </ p>",
comments: []
});
Each comment is an object of type:
NEW_COMMENT = {
content: "Thanks! Great article! Peshi is4o!",
author: "vasily@example.com"
}
The graph shows the performance of the operation
db.blog.update({title: "new post"}, {"$push": {comments: NEW_COMMENT}}, true )
(the last parameter enables upsert mode) depending on the size of the
blog.comments
array and having an index on
blog.title
.
Focus on inSERT
results

Comments
The same case, but the title of the post all the time generate randomly. Meaning - the frequent posting of new articles through the upsert.
It can be seen that with a small number of records (small base), the index is not needed. But with the growth of the base and the increase in the number of extents, the index begins to help and gives a stable write speed.
Results
My verses upsert'am such: you can use when you can not say exactly what more - document changes or adding new ones, or their ratio is about 50/50. In my environment, the "head-on" recording goes at a speed of 10K documents per second.
Experimenters: pay attention to the size of the document, how many extents it occupies (nscanned). With the increase in the number of extents, the picture will be the same as on the first graph, but it will degrade more abruptly.