Simplified query 6.

This commit is contained in:
K 2024-11-10 12:16:58 +05:30
parent 0e41344f45
commit 61af64c72e
Signed by: notkshitij
GPG Key ID: C5B8BC7530F8F43F

View File

@ -168,14 +168,14 @@ for (let i = 1; i <= 10000; i++) {
db.Employee.insertOne({ db.Employee.insertOne({
Emp_id: i, Emp_id: i,
Name: `Employee ${i}`, Name: `Employee ${i}`,
Designation: `${Math.floor(Math.random() * 5) + 1}` Designation: `Work ${i*5}`
}); });
} }
// Wait for it to insert 10000 documents // Wait for it to insert 10000 documents!
// Time without index // Time without index
let startTime = new Date(); let startTime = new Date();
db.Employee.find({ Emp_id: 7500 }).toArray(); db.Employee.find({ Emp_id: 7500 })
let endTime = new Date(); let endTime = new Date();
print("Time taken to search without index: " + (endTime - startTime) + " ms"); print("Time taken to search without index: " + (endTime - startTime) + " ms");
@ -184,7 +184,7 @@ db.Employee.createIndex( { Emp_id: 1 });
// Time with index // Time with index
startTime = new Date(); startTime = new Date();
db.Employee.find({ Emp_id: 7500 }).toArray(); db.Employee.find({ Emp_id: 7500 })
endTime = new Date(); endTime = new Date();
print("Time taken to search with index: " + (endTime - startTime) + " ms"); print("Time taken to search with index: " + (endTime - startTime) + " ms");