4

您可以在他们的官方文档中的示例中看到它: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

为什么名称设置为1和类型设置为-1

4

1 回答 1

7

来自 mongodb 文档

排序

索引以升序 (1) 或降序 (-1) 排序顺序存储对字段的引用。

见这里:https ://docs.mongodb.org/manual/core/index-compound/

所以,按照你的例子,name正在上升,type正在下降

于 2015-11-23T12:36:40.893 回答