E
E
EgorLee2021-06-21 02:22:58
MongoDB
EgorLee, 2021-06-21 02:22:58

How to remove an array element in mongoDB?

There is a given structure in MongoDB
60cfcd6bbad87044440489.jpeg
How can I find the element that is highlighted in red and remove only that element from the array?
Tried
db.online_service.update_one({'id': 'inst'}, {'$pull': {'accounts_data.$': {'id': 'inst_f18+'}}})
db.online_service.update_one({' id': 'inst'}, {'$pull': {'accounts_data.$.id': 'inst_f18+'}})
and various variations, but to no avail.
Thanks in advance for your reply

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Inviz Custos, 2021-06-21
@MvcBox

General example (edit for yourself):

db.online_service.update(
    { },
    { $pull: { accounts_data: { $elemMatch: { id: "inst_f18+" } } } }, 
    { multi: true }
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question