V
V
vleypi2021-10-15 19:33:35
MongoDB
vleypi, 2021-10-15 19:33:35

How to update each object key in an array in mongoDb?

I have such a record. And I want each user who is in the users array to reset their points to 0.

How to do this?

One has -1000, the other has 2312, you need to make one request so that both have 0, is this possible?

6169acb58b584236252792.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vleypi, 2021-10-15
@vleypi

Here is the solution to the issue:

await Lobby.findOneAndUpdate({"_id": lobby},{$set: {"users.$[].points": 0}})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question