You can see it in the example in their official docs: guide#indexes.
var animalSchema = new Schema({
name: String,
type: String,
tags: { type: [String], index: true } // field level
});
animalSchema.index({ name: 1, type: -1 }); // schema level
Why is name set to 1
and type set to -1
?
From the mongodb docs
Sort Order
Indexes store references to fields in either ascending (1) or descending (-1) sort order.
See here: https://docs.mongodb.org/manual/core/index-compound/
So, as per your example, name
is ascending, type
is desecending
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With