E
E
Epol Pers2019-10-22 18:56:13
JavaScript
Epol Pers, 2019-10-22 18:56:13

How to properly update documents in MongoDB database?

Hello. There was such a question, but first I’ll explain the essence. There is a site parser application and there is a mongoDb database where the parser sends objects with product data using the save () method. The problem is that most of the files in the database do not need to be updated, should they be filtered on the application side, i.e. first request all objects from the database, check them on the application side and then send unique ones to the database, or it’s more profitable to just send all objects using the save () method, and then let MongoDB figure out what it needs to update and what not to update.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2019-10-22
@idx12x4xxx

where the parser sends objects with product data using the save() method

see bulkWrite to make not "300 to 10000" requests but one
https://docs.mongodb.com/manual/reference/method/d...
usage example
https://stackoverflow.com/a/47099622
i would So I tried it - to collect the updateOne array from everything that needs to be updated / written to the monga, and would send one bulkWrite (array), let the monga figure out what to do with it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question