我正在尝试为我的架构/模型制作一个编号的二级索引,例如:0,1,2,...,所以我检查了关于索引的mongoose文档 . 他们似乎有两种方法可以做到这一点:“使用mongoose,我们在路径级别或模式级别的Schema中定义这些索引 . ”(引用文档) . 我尝试了这两种方法,似乎一切正常就像之前一样,但是没有为添加到集合中的项添加索引,也没有错误 . 这是我的代码:var mongoose = require('mongoose');

var BlogSchema = new mongoose.Schema({

title: {
    type: String,
    required: true,
    minlength: 1,
    trim: true
},
content: {
    type: String,
    required: true,
    minlength: 1,
    trim: true
},
_creator: {
    type: mongoose.Schema.Types.ObjectId,
    required: true
},
_creatorUser: {
    type: String,
    required: true,
    minlength: 6
},
_createdAt: {
    type: Number,
    required: true,
}
})


var Blog = mongoose.model('Blog', BlogSchema)


Blog.on('index', (err) => {
if (err) {
    console.log(err)
}
})

module.exports = {Blog};

我尝试将其添加到Schema结构:tags:{type:[String],index:true}也尝试在Schema结构下面添加它:BlogSchema.index({name:1,type:-1})并尝试使用在同一时间,似乎没有任何工作,我花了几个小时在这上面,只是不能让它工作 . 请帮忙