![]() To this method you need to pass an array of documents. You can insert multiple documents using the insertMany() method. Syntaxįollowing example creates a new collection named empDetails and inserts a document using the insertOne() method. If you need to insert only one document into a collection you can use this method. If you specify _id then it will replace whole data of document containing _id as specified in save() method. If you don't specify _id in the document then save() method will work same as insert() method. To insert the document you can use db.post.save(document) also. You can also pass an array of documents into the insert() method as shown below.ĭescription: "MongoDB is no SQL database",ĭescription: "NoSQL database doesn't have tables", _id: ObjectId(4 bytes timestamp, 3 bytes machine id, 2 bytes process id, 3 bytes incrementer) _id is 12 bytes hexadecimal number unique for every document in a collection. In the inserted document, if we don't specify the _id parameter, then MongoDB assigns a unique ObjectId for this document. ![]() If the collection doesn't exist in the database, then MongoDB will create this collection and then insert a document into it. Here mycol is our collection name, as created in the previous chapter. description: "MongoDB is no sql database", The basic syntax of insert() command is as follows − To insert data into MongoDB collection, you need to use MongoDB's insert() or save() method. ![]() In this chapter, we will learn how to insert document in MongoDB collection.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |