Mongodb Sample Querying Indexing
Mongodb Sample Querying Indexing
You are working as a database engineer for a student information system that stores student
records in a MongoDB collection named students, with fields such as stud_regno, name, cgpa,
and contact_no. Write MongoDB commands to perform the following operations: create and
select a database, create a collection, insert one and multiple student records, query students based
on cgpa using logical and comparison operators, display all records, project specific fields, update
contact information, sort data by CGPA, create and manage indexes, delete specific or multiple
records, drop the collection, and finally drop the database.
// 2. Create a collection
> db.createCollection("students")
{ "ok" : 1 }
// 9. CGPA != 6.0
> db.students.find({ cgpa: { $ne: 6.0 } }).pretty()
// Returns all records except those with cgpa == 6.0
{ "nIndexesWas" : 2, "ok" : 1 }
{ "ok" : 1 }