Priority: Major - P3
Affects Version/s: 2.4.10
Fix Version/s: None
I would like to either insert or update a record in a time series collection and do this in one pass with a update() command with the $setOnInsert and $inc commands.
I would like to avoid querying to find out if the record exists and then doing an insert if it does not exist or an update increment if the record does exist.
For example: This does not work:
But this does.
Then if record exists:
Else if the record doesn't exist, then do an insert.
If I do the query and then the if test, for every single event, I have to access the database twice - one to query the document to see if it exists and then again to insert or update the record.
What is a better strategy? How can I access the database once to upsert the document in this time series collection. This collection is being updated millions of times a day. I'd like to increase my performance.