You might want to assign indexes to specific fields that you frequently use to find documents. You can apply indexes to a schema object when defining the schema or by using the index(fields)
command. For example, both of the following add an index
to the name
field, in ascending order:
var schema = new Schema({
name: {type: String, index: 1}
};
//or
var schema = new Schema({name: String)};
schema.index({name:1});
You can get a list of indexed fields on a schema object by using the indexes()
method. For example:
schema.indexes()