On this page
Update Documents
- Mongo Shell
- Compass
- Python
- Java (Sync)
- Node.js
- Other
- PHP
- Motor
- Java (Async)
- C#
- Perl
- Ruby
- Scala
This page provides examples of how to update documents in using the following methods in the mongo
shell:
db.collection.updateOne(<filter>, <update>, <options>)
db.collection.updateMany(<filter>, <update>, <options>)
db.collection.replaceOne(<filter>, <replacement>, <options>)
The examples on this page use the inventory
collection. To create and/or populate the inventory
collection, run the following:
This page provides examples of how to update documents in MongoDB Compass .
The examples on this page use the inventory
collection. Populate the inventory
collection with the following documents:
This page provides examples of how to update documents using the following methods in the PyMongo Python driver:
pymongo.collection.Collection.update_one()
pymongo.collection.Collection.update_many()
pymongo.collection.Collection.replace_one()
The examples on this page use the inventory
collection. To create and/or populate the inventory
collection, run the following:
This page provides examples of how to update documents using the following methods in the Java Synchronous Driver :
- com.mongodb.client.MongoCollection.updateOne
- com.mongodb.client.MongoCollection.updateMany
- com.mongodb.client.MongoCollection.replaceOne
The examples on this page use the inventory
collection. To create and/or populate the inventory
collection, run the following:
This page provides examples of how to update documents using the following methods in the MongoDB Node.js Driver :
The examples on this page use the inventory
collection. To create and/or populate the inventory
collection, run the following:
This page provides examples of how to update documents using the following methods in the MongoDB PHP Library :
The examples on this page use the inventory
collection. To create and/or populate the inventory
collection, run the following:
This page provides examples of how to update documents using the following methods in the Motor driver:
motor.motor_asyncio.AsyncIOMotorCollection.update_one()
motor.motor_asyncio.AsyncIOMotorCollection.update_many()
motor.motor_asyncio.AsyncIOMotorCollection.replace_one()
The examples on this page use the inventory
collection. To create and/or populate the inventory
collection, run the following:
This page provides examples of how to update documents using the following methods in the Java Reactive Streams Driver :
- com.mongodb.reactivestreams.client.MongoCollection.updateOne
- com.mongodb.reactivestreams.client.MongoCollection.updateMany
- com.mongodb.reactivestreams.client.MongoCollection.replaceOne
The examples on this page use the inventory
collection. To create and/or populate the inventory
collection, run the following:
This page provides examples of how to update documents using the following methods in the MongoDB C# Driver :
The examples on this page use the inventory
collection. To create and/or populate the inventory
collection, run the following:
This page provides examples of how to update documents using the following methods in the MongoDB Perl Driver :
- MongoDB::Collection::update_one()
- MongoDB::Collection::update_many()
- MongoDB::Collection::replace_one()
The examples on this page use the inventory
collection. To create and/or populate the inventory
collection, run the following:
This page provides examples of how to update documents using the following methods in the MongoDB Ruby Driver :
The examples on this page use the inventory
collection. To create and/or populate the inventory
collection, run the following:
This page provides examples of how to update documents using the following methods in the MongoDB Scala Driver :
The examples on this page use the inventory
collection. To create and/or 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: "canvas", qty: 100, size: { h: 28, w: 35.5, uom: "cm" }, status: "A" },
{ item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
{ item: "mat", qty: 85, size: { h: 27.9, w: 35.5, uom: "cm" }, status: "A" },
{ item: "mousepad", qty: 25, size: { h: 19, w: 22.85, uom: "cm" }, status: "P" },
{ 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" },
{ item: "sketchbook", qty: 80, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
{ item: "sketch pad", qty: 95, size: { h: 22.85, w: 30.5, uom: "cm" }, status: "A" }
] );
You can run the operation in the web shell below:
https://mws.mongodb.com/?version=3.6