On this page
Delete Documents
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
This page provides examples of delete operations using the following methods in the mongo
shell:
The examples on this page use the inventory
collection. To populate the inventory
collection, run the following:
This page provides examples of deleting documents using MongoDB Compass .
Populate the inventory
collection with the following documents:
This page provides examples of delete operations using the following methods in the PyMongo Python driver:
The examples on this page use the inventory
collection. To populate the inventory
collection, run the following:
This page provides examples of delete operations using the following methods in the Java Synchronous Driver :
The examples on this page use the inventory
collection. To populate the inventory
collection, run the following:
This page provides examples of delete operations using the following methods in the MongoDB Node.js Driver :
The examples on this page use the inventory
collection. To populate the inventory
collection, run the following:
This page provides examples of delete operations using the following methods in the MongoDB PHP Library :
The examples on this page use the inventory
collection. To populate the inventory
collection, run the following:
This page provides examples of delete operations using the following methods in the Motor driver:
motor.motor_asyncio.AsyncIOMotorCollection.delete_many()
motor.motor_asyncio.AsyncIOMotorCollection.delete_one()
The examples on this page use the inventory
collection. To populate the inventory
collection, run the following:
This page provides examples of delete operations using the following methods in the Java Reactive Streams Driver :
- com.mongodb.reactivestreams.client.MongoCollection.deleteMany
- com.mongodb.reactivestreams.client.MongoCollection.deleteOne
The examples on this page use the inventory
collection. To populate the inventory
collection, run the following:
This page provides examples of delete operations using the following methods in the MongoDB C# Driver :
The examples on this page use the inventory
collection. To populate the inventory
collection, run the following:
This page provides examples of delete operations using the following methods in the MongoDB Perl Driver :
The examples on this page use the inventory
collection. To populate the inventory
collection, run the following:
This page provides examples of delete operations using the following methods in the MongoDB Ruby Driver :
The examples on this page use the inventory
collection. To populate the inventory
collection, run the following:
This page provides examples of delete operations using the following methods in the MongoDB Scala Driver :
The examples on this page use the inventory
collection. To populate the inventory
collection, run the following:
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
db.inventory.insertMany( [
{ item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
{ item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "P" },
{ item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" },
{ item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" },
{ item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" },
] );
You can run the operation in the web shell below:
https://mws.mongodb.com/?version=3.6[
{ item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
{ item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "P" },
{ item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" },
{ item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" },
{ item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" },
]
For instructions on inserting documents in MongoDB Compass, see Insert Documents.
Note
For complete reference on inserting documents in MongoDB Compass, see the Compass documentation .
db.inventory.insert_many([
{"item": "journal",
"qty": 25,
"size": {"h": 14, "w": 21, "uom": "cm"},
"status": "A"},
{"item": "notebook",
"qty": 50,
"size": {"h": 8.5, "w": 11, "uom": "in"},
"status": "P"