mongodb command remove by _id
To remove a document from a MongoDB collection by its _id
field, you can use the deleteOne
or deleteMany
method along with the _id
filter. Here's an example of how to do it in BASIC:
db.collection.deleteOne { "_id": ObjectId("your_id_here") }
Replace "your_id_here"
with the actual _id
value of the document you want to remove.
Please note that the above example assumes you are using the MongoDB shell. If you are using a different programming language or framework, the syntax may vary slightly, but the general concept remains the same.