DEV Community

Discussion on: Implementing Time Series in MongoDB

Collapse
 
cog_g profile image
Constantin Guay

Hi, why don't you save one step by doing the insert right away?

According to the doc insert won't return 1 if the document was existing, and so you can do the insert, then the update.

In fact, you might even not have to check the returned value of the insert, as it doesn't matter.

What do you think?

-- Constantin

Collapse
 
riccardo_cardin profile image
Riccardo Cardin

Hello Constantin,

in my scenario the use case in which the document will be already available is far away the most frequent. So, in the majority of cases, step one will be the only one that the procedure will take.

Under these conditions, the approach described in the article should be the optimal one.

Cheers,

Riccardo