Here are the MongoDB shell commands to create the "students" and "courses" collections, and to populate them with sample data:
First, use the use command to switch to the database where you want to create the collections. For example, if you want to use a database named "college", run:
use college
Next, create the "students" collection using the db.createCollection() method:
db.createCollection("students")
To insert data into the "students" collection, use the db.collection.insertMany() method. Here's an example of how to insert the sample data:
db.students.insertMany([
{
"Name": "John Doe",
"Age": 20,
"Gender": "Male",
"Email": "johndoe@example.com",
"Phone Number": "1234567890",
"Address": "123 Main St, Anytown USA"
},
{
"Name": "Jane Smith",
"Age": 19,
"Gender": "Female",
"Email": "janesmith@example.com",
"Phone Number": "0987654321",
"Address": "456 Elm St, Anytown USA"
Want to print your doc? This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (