Mongodb index on single field

Create an index on the studentId field of the students collection. 1 means index it in ascending and -1 means descending.

db.students.createIndex({studentId: 1});

With the above index, the following query will be using the studentId index for finding the results.

db.students.find({studentId: 3});
db.students.find({studentId: {$gt: 30}});

Show existing indexes in the students collection.


Drop index

db.students.dropIndex({studentId: 1});

Search within Codexpedia

Custom Search

Search the entire web

Custom Search