How do i insert a document into a collection in mongodb?
-
Related:
How do i read a collection in mongodb?
How do i update a collection on mongodb?
How do i delete a document in a collection on mongodb?MongoDB shell methods: https://docs.mongodb.com/manual/reference/method/
Inserts a document into a collection.
Using the insertOne method: https://docs.mongodb.com/manual/reference/method/db.collection.insertOne/#db.collection.insertOne
Create a variable.
> software = {"Company" : "MongoDB", "Type" : "Document Oriented Database", "Year" : 2009 } { "Company" : "MongoDB", "Type" : "Document Oriented Database", "Year" : 2009 }
Insert a document into a collection named softwarelist. We created a variable already with what we want to insert.
> db.softwarelist.insertOne(software) { "acknowledged" : true, "insertedId" : ObjectId("5c263b8b4ef440e31fc0405f") }
View the saved collection.
> db.softwarelist.find() { "_id" : ObjectId("5c24e11ba7354c80abcfb1f2"), "Company" : "MongoDB", "Type" : "Document Oriented Database", "Year" : 2009 }
© Lightnetics 2024