Use db.collection.insert() method to insert new document to MongoDB collection. You don’t need to create the collection first. Insert method will automatically create collection if not exists.
Syntax
Insert Single Document
Insert single ducument using the insert() method. It’s required a json format of document to pass as arguments.
Output:
Insert Multiple Documents
To insert multiple documents in single command. The best way to create an array of documents like following:
Now pass the array as argument to insert() method to insert all documents.
Output: