I am trying to make a numbered secondary Index for my Schema/Model eg: 0,1,2,... , so i checked out the mongoose docs about indexes. they seem to have 2 ways to do that : "With mongoose, we define these indexes within our Schema at the path level or the schema level."(quote from the docs).I tried both of these methods and it seems that everything works just like before but there is no index added to items added to the collection and there are also no errors. Here is my code: 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};
i tried adding this to the Schema structure: tags: { type: [String], index: true } also tried adding this below the Schema structure: BlogSchema.index({ name: 1, type: -1 }) and also tried using both the same time, nothing seems to work, i spent hours over this and just cant make it work. Please Help