
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
MongoDB query to update field and modify the data currently in column
For this, use find() along with update(). Let us create a collection with documents −
> db.demo115.insertOne({"LastName":"Brown"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2efe9bd8f64a552dae635a") }
Display all documents from a collection with the help of find() method −
> db.demo115.find();
This will produce the following output −
{ "_id" : ObjectId("5e2efe9bd8f64a552dae635a"), "LastName" : "Brown" }
Following is the query to update field and modify the data currently in column −
> db.demo115.find({"LastName":"Brown"}).forEach(function(d) { ... db.demo115.update({_id: d._id}, {$set: {LastName: 'Hello ' + d.LastName}}); ... })
Display all documents from a collection with the help of find() method −
> db.demo115.find();
This will produce the following output −
{ "_id" : ObjectId("5e2efe9bd8f64a552dae635a"), "LastName" : "Hello Brown" }
- Related Articles
- MongoDB query to update array with another field?
- How to run MongoDB query to update only a specific field value?
- MongoDB query to update each field of documents in collection with a formula?
- Update _id field in MongoDB
- MongoDB query to update tag
- How to update _id field in MongoDB?
- MongoDB query to update the nested document?
- How to update or modify the existing documents of a collection in MongoDB?
- MongoDB query to update selected fields
- MongoDB query to update nested document
- Want to update inner field in a MongoDB
- Combine update and query parts to form the upserted document in MongoDB?
- Update MongoDB field using value of another field?
- MongoDB query to update a MongoDB row with only the objectid
- MongoDB query to update only certain fields?

Advertisements