H
H
Hanry6542020-09-29 17:52:03
MongoDB
Hanry654, 2020-09-29 17:52:03

How to remove object from mongodb?

How can I remove list with id 4?

let services = {
        "1" : {
            "list" : {
                "4" : {
                    "id" : 4,
                    "desc" : "Lore ipsum",
                    "price" : 30,
                    "min" : 100,
                    "max" : 5000
                },
                "25" : {
                    "id" : 25,
                    "desc" : "Lore ipsum",
                    "price" : 50,
                    "min" : 100,
                    "max" : 5000
                }
            }
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-09-29
@Hanry654

not entirely clear what the collection schema looks like, but $unset
https://docs.mongodb.com/manual/reference/operator...

Service.updateOne(
  { services: 1 /* * */ }, 
  { $unset: { '4': '' } }
)

// не сработает, потому что я не понимаю, как именно выделить этот документ

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question