8. students
db.students.insertMany([ { "studentID": 1,
"name": "Student1", "age": 22, "city":
"New York", "tags": ["tag1", "tag2",
"tag3"] }, { "studentID": 2, "name":
"Student2", "age": 25, "city": "San
Francisco", "tags": ["tag1", "tag2",
"tag3"] }, { "studentID": 3, "name":
"Student3", "age": 30, "city": "Los
Angeles", "tags": ["tag1", "tag2",
"tag3"] }, { "studentID": 4, "name": "Student4",
"age": 35, "city": "Chicago", "tags":
["tag1", "tag2", "tag3"] }, {
"studentID": 5, "name": "Student5",
"age": 40, "city": "New York", "tags":
["tag1", "tag2", "tag3"] }, {
"studentID": 6, "name": "Student6",
"age": 45, "city": "San Francisco", "tags":
["tag1", "tag2", "tag3"] }, {
"studentID": 7, "name": "Student7",
"age": 50, "city": "Los Angeles",
"tags": ["tag1", "tag2", "tag3"] }, {
"studentID": 8, "name": "Student8",
"age": 20, "city": "Chicago", "tags":
["tag1", "tag2", "tag3"] }, { "studentID":
9, "name": "Student9", "age": 28,
"city": "New York", "tags": ["tag1",
"tag2", "tag3"] }, { "studentID": 10,
"name": "Student10", "age": 32, "city":
"San Francisco", "tags": ["tag1",
"tag2", "tag3"] }, { "studentID": 11,
"name": "Student11", "age": 26, "city":
"Los Angeles", "tags": ["tag2", "tag3"]
}, { "studentID": 12, "name": "Student12",
"age": 33, "city": "Chicago", "tags":
["tag1", "tag3"] }, { "studentID": 13,
"name": "Student13", "age": 27, "city":
"New York", "tags": ["tag1", "tag2"] },
{ "studentID": 14, "name": "Student14",
"age": 31, "city": "San Francisco",
"tags": ["tag1", "tag2", "tag3"] }, {
"studentID": 15, "name": "Student15",
"age": 36, "city": "Los Angeles",
"tags": ["tag2", "tag3"] }, {
"studentID": 16, "name": "Student16",
"age": 38, "city": "Chicago", "tags":
["tag1", "tag2"] }, { "studentID": 17,
"name": "Student17", "age": 29, "city":
"New York", "tags": ["tag1", "tag3"] },
{ "studentID": 18, "name": "Student18",
"age": 34, "city": "San Francisco",
"tags": ["tag1", "tag2", "tag3"] }, {
"studentID": 19, "name": "Student19",
"age": 23, "city": "Los Angeles",
"tags": ["tag1", "tag2"] }, {
"studentID": 20, "name": "Student20",
"age": 39, "city": "Chicago", "tags":
["tag1", "tag2", "tag3"] }] );
db.students.createIndex({ studentID: 1 }, { unique: true });
db.students.createIndex({ city: 1 }, { sparse: true });
db.students.createIndex({ tags: 1 });
db.students.createIndex({ city: 1, age: 1 });
db.students.getIndexes();
8B
db.students.find({}).sort({age: -1}).limit(1);
db.students.find({}).sort({age: -1}).limit(1).explain();
db.students.find({}).sort({age: -1}).limit(1).explain("executionStats");
db.students.find({}).sort({age:1}).limit(1).explain("executionStats").executionStats.totalDocsExamined;
db.students.find({}).sort({age:
-1}).limit(1).explain("executionStats").executionStats.executionTimeMillis;
Comments
Post a Comment