S
S
Stepgor2020-07-13 03:09:17
Node.js
Stepgor, 2020-07-13 03:09:17

Ways to update a lot of Mongodb objects?

It is necessary to periodically update the database of 20k objects. I want to give 2 solutions, if you know better solutions, write.
1. We turn to the database and take all the objects, then we do everything we need with them, delete all the old objects from the table and insert new ones

Model.find({}, (err, data) => {
    //work with data
   Model.deleteMany({}, () => {
      Model.insertMany(data)
   })
})


2. Create one object in the database and in its property, let's say data, store an array of objects, when necessary - take and change, and then update 1 object in the database.

If there are other more correct and productive approaches, please comment

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Robur, 2020-07-13
@Stepgor

1. why do you need to delete everything first, then create it? try https://docs.mongodb.com/manual/reference/method/d... compare the speed, whichever is faster and use it.
2. in general, some kind of perversion, so it's easier for you to just json - keep the file in the cloud - it will be read / updated faster.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question