E
E
EgorLee2021-06-05 18:13:37
MongoDB
EgorLee, 2021-06-05 18:13:37

How to add an element to a specific nested array in MongoDB?

60bb93d5a9269780439881.jpeg

There is this document, is it possible to somehow insert a new element into the nested array "accounts_data.0.accounts", but not by such a request, but by searching for accounts_data.name?
For example find an array where the field "name" = 'instagram w. 18+' and add a new element to its accounts field

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Romanov, 2021-06-05
@EgorLee

It's possible, like this:

db.test.updateOne({"accounts_data.name": "instagram ж. 18+"}, {$push: {"accounts_data.$.accounts": 1} })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question