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 |
|
writeConcern | document |
|
ordered | boolean |
|
Sample Query1 :
show collections --display the created collection db.wikitechy4.insert({"websitename":"wikitechy.com" , "details" : "learn mongodb basics and step by step", "author" : "venkat" })
Output
- 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" })
Output
- 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.