Insert Statement
Open MongoDB Shell
- Open the MongoDB Shell from Linux shell
- Switch to our "employee" database
# mongosh
Current Mongosh Log ID: 6117225c105379b62b6abaa9
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000
Using MongoDB: 5.0.2
Using Mongosh: 1.0.5
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
test>
# use employee
switched to db employee
Insert Single Record
- Run following command to insert one record to "emp_info" collection
employee> db.emp_info.insertOne( { first:"John", last:"Davis", role:"Dev"} )
{
acknowledged: true,
insertedId: ObjectId("61172935a1766234eab5b87a")
}
Insert Multiple Records
- Run following command to insert multiple record to "emp_info" collection
employee> db.emp_info.insertMany( [ { first:"Allan", last:"Coller", role:"CM" }, {first:"Sam", last:"Doe", role:"Manager" } ] )
{
acknowledged: true,
insertedIds: {
'0': ObjectId("61172c1ca1766234eab5b87e"),
'1': ObjectId("61172c1ca1766234eab5b87f")
}
}