Mongodb Insert Collection - MongoDB Tutorial
Mongodb Insert Collection
- In mongoDB all the datas are stored in document oriented types they are called as “collection”.
- All data stored into the collection are in BSON format.
Syntax
db.collection.insert()
Here in this syntax we can Insert a 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 Query 1
show collections --display the created collection
db.wikitechy4.insert({"websitename":"wikitechy.com",
"details" : "learn mongodb basics and step by step",
"author" : "venkat"
}) --insert data in a collection
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” query where 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 row in the “wikitechy4” collection using insert rich query where the data are inserted successfully as shown above.