Editing a collection

db.collection.update(query, update)
query: An object for finding the document
Example: {"name":"shilpi"}
update: An object for updating the document with set command
Example: {$set:{"age":"23"}}

To edit a mongodb collection update function is used

Apply the query for finding the document which you want to update. In our collection we want to update collection having name as shilpi so query is:

{"name":"shilpi"}

Using the set command to modify the Field Name

Choose which Field Name you want to modify and then enter the new value accordingly into the query. In our collection we want to edit age value to 23 for name shilpi:

{$set:{"age":"23"}}

Defining, Creating and Dropping a MongoDB collection

MongoDB, the most popular NoSQL database, is an open-source document-oriented database. The term ‘NoSQL’ means ‘non-relational’. It means that MongoDB isn’t based on the table-like relational database structure but provides an altogether different mechanism for storage and retrieval of data.

Similar Reads

Document

It is the basic unit of MongoDB and a single record inside a collection is known as a document. It is a JSON object which has the data in the form of key-value pairs....

Collection

It is the grouping of documents. A collection belongs to a single database inside MongoDB. The collection the contains the data in the form of document just like the table of RDBMS which contains the data in the form of rows and columns....

Creating a MongoDB a collection

As a collection belongs to a single database so first we will have to create a database for creating a collection...

Inserting Documents in the Collection

Inserting only one document at a time...

Editing a collection

...

Dropping the collection

...

Contact Us