MongoDB - Insert Document

MongoDB - Insert Document : In this chapter, we can discover ways to insert document in MongoDB series.

The insert() Method

To insert statistics into MongoDB series, you want to apply MongoDB's insert() or save() technique.


There are following primary syntax of insert() command -


   _id: ObjectId(7df78ad8902c),
   name: 'MongoDB Overview', 
   description: 'MongoDB is not any square database',
   by means of: 'tutorials factor',
   url: 'http://www.Welookups.Com',
   tags: ['mongodb', 'database', 'NoSQL'],
   likes: one hundred

Here mycol is our series name, as created within the previous chapter. If the collection does not exist within the database, then MongoDB will create this collection after which insert a document into it.

_id is 12 bytes hexadecimal number particular for every file in a group.

_id: ObjectId(4 bytes timestamp, 3 bytes device identification, 2 bytes system identity, three bytes incrementer)

To insert more than one files in a unmarried query, you could pass an array of files in insert() command.


      identify: 'MongoDB Overview', 
      description: 'MongoDB is not any square database',
      through: 'tutorials point',
      url: 'http://www.Tutorialspoint.Com',
      tags: ['mongodb', 'database', 'NoSQL'],
      likes: one hundred
      identify: 'NoSQL Database', 
      description: "NoSQL database would not have tables",
      by using: 'welookups',
      url: 'http://www.Welookups.Com',
      tags: ['mongodb', 'database', 'NoSQL'],
      likes: 20, 
      comments: [	
            message: 'My first comment',
            dateCreated: new Date(2013,11,10,2,35),
            like: zero 

To insert the file you could use db.Post.Store(document) additionally. If you don't specify _id within the file then store() technique will paintings same as insert() technique. If you specify _id then it will update whole records of file containing _id as specified in keep() technique.

Welookups is optimized for learning.Copy right 2018 - 2019 kumar aditya singh .
All Right Reserved and you agree to have read and accepted our term and condition.
All Rights Reserved.