Skip to main content


Showing posts from May, 2015

Insert Document in MongoDB's Collection

We can use insert() or save() methods to insert document(data) in  collection MongoDB. Syntax                                                                                                                Basic syntax of insert() command is as follows:



>db.mycol.insert({    _id: ObjectId(7df78ad8902c),    title: 'MongoDB Overview',    description: 'MongoDB is no sql database',    by: 'Codefari',    url: '',    tags: ['mongodb', 'database', 'NoSQL'],    likes: 100 })

mycol is collection name, MongoDB will create collection if doesn't exist in the database then insert document into it. to know how to create collection click here. if we did not specify the _id parameter, MongoDB assign a unique Object_Id for this document. _id is 12 bytes hexadecimal number unique for every document in a collection. 12 bytes are divided as follows:

_id: ObjectId(4 bytes timestamp, 3…