A
A
Alexander2020-10-21 12:26:40
MongoDB
Alexander, 2020-10-21 12:26:40

What is the best way to update all values ​​in the database?

I have an array of objects. So far they are doing this, but it turns out that I update 1 instance each time, and this is not correct.

const arr = await model.find({})
arr .forEach(async instanse => {
      await model.update(
            { _id: instanse._id },
            { $set:  {key1: value1, key2: value2}) }
      )
})

Each object has its own new field values, taken from the array of new values. Instead of an object after $set - a function returning an object

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question