How do I delete a specific document from a Collection in Mongodb?

Asked

Viewed 4,579 times

0

The method remove() used this way: db.name_da_collection.remove(), remove all Documents from a Collection, as I do to remove a specific Document?

  • @Gustavomesquita posts the Collection data you want to remove.

1 answer

1


If you want to remove by id you can use the following query:

db.collection.remove({"_id": ObjectId("5798ffcd60b2d8a4066b482d")});

You can remove using the same structure as a find. For example, you can remove all records that are larger than 10.

db.collection.remove({quantidade : {$gt :10}})
  • http://stackoverflow.com/questions/4932928/remove-by-id-in-mongodb-console

  • How do I remove? Do I have to enter the installation folder and type the above command? With me you’re saying that this command is not recognized and such

Browser other questions tagged

You are not signed in. Login or sign up in order to post.