Insert Multiple Data in MongoDB

Insert Multiple Data in MongoDB


Insert Multiple Data in MongoDB

1. Create a json file as below 

cat demo.js

collection = db["dummy_collection"]
db.test_collection.insertMany([
    {"name": "Alice", "age": 30, "city": "New York"},
    {"name": "Bob", "age": 25, "city": "San Francisco"},
    {"name": "Charlie", "age": 35, "city": "Los Angeles"},
    {"name": "David", "age": 28, "city": "Chicago"},
    {"name": "Eve", "age": 22, "city": "Miami"}
]);

2. Run with mongosh or mongod

mongosh --host "<hostname:port>" --username  --password demo.js 

Post a Comment

Previous Post Next Post