To insert data into MongoDB collection, you can use MongoDB's insert() or save() method.
Basic syntax of insert() command is as follows
Here mycol is the collection name which we created in the previous chapter. If the collection does not exist in the database, MongoDB will create this collection and then inserts a document into it.
In the inserted document, if _id parameter is not specified, then MongoDB will assign a unique ObjectId for this document.
_id is 12 bytes hexadecimal number unique for every document in a collection. 12 bytes are divided as follows
To insert multiple documents in a single query, pass an array of documents in insert() command.
To insert the document, use db.post.save(document) can also be used. If _id is not specified in the document, then save() method will work same as insert() method. If _id is specified, then it will replace whole data of document containing _id as specified in save() method.
MongoDB Related Interview Questions
|Python Interview Questions||C & Data Structures Interview Questions|
|Hadoop Interview Questions||Node.js Interview Questions|
|Scala Interview Questions||Socket Programming Interview Questions|
|HBase Interview Questions||Solaris Administrator Interview Questions|
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.