Mongodb compound index

Create a compound index on the studentId and class fields of the students collection. 1 means index it in ascending and -1 means descending.

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

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

db.students.find({"studentId": 3, "class": "math"});

Show existing indexes in the students collection.


Search within Codexpedia

Custom Search

Search the entire web

Custom Search