Mongodb Insert Row in Collection - MongoDB Tutorial




Mongodb Insert Row in Collection

  • In mongoDB all the row of datas are stored in the document oriented types they are called as “collection”.
  • All data stored into the collection are in BSON (Binary Script Object Notation) format.

Syntax :

db.collection.insert()  

Here in this syntax we can Insert the document or documents into a collection.

Syntax for version 2.6 insert query :

db.collection.insert(
   <document or array of documents>,
   {
     writeConcern: <document>,
     ordered: <boolean>
   }
)

Parameters Type Description
document document (or) array
  • A document (or) array of documents to insert into the collection.
writeConcern document
  • Optional. A document expressing the write concern. Omit to use the default write concern.
ordered boolean
  • Optional.
  • If true, perform an ordered insert of the documents in the array, and if an error occurs with one of the documents, MongoDB will return without processing the remaining documents in the array.
  • If false, It performs an unordered insert, and if an error occurs with one of documents, continue processing the remaining documents in the array.

Sample Query1 :

show collections               --display the created collection
db.wikitechy4.insert({"websitename":"wikitechy.com" , 
"details" : "learn mongodb basics and step by step", 
"author" : "venkat"
})   
MongoDb


Output

MongoDb
  • In this statement we display the table (or) collections.
  • Here in this statement we insert a data in the collection “wikitechy4” using “db.wikitechy4.insert” rich query and the data written successfully.

Sample Query 2 :

db.wikitechy4.insert({"websitename":"wikitechy.com" ,
"details" : "next row inserted", 
"articlecount":"40",
"author" : "jln"
})

MongoDb

Output

MongoDb

  1. Here in this statement, we are adding another data in the collection “wikitechy4” using insert rich query, where the data’s are inserted successfully as shown above.


Related Searches to Mongodb Insert Row in Collection - MongoDB Tutorial

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×