I recently started using Mongoose (v.3.2.1) and I am having problems with indexes.
I define a pair of indexes of my schema (Schema.path ('attr'). Index (true)) and they are not created in the database. (I run db.collection.getIndexKeys () in the shell, and I only see the _id index).
Note that some / all indexes are sometimes created.
I turned on debugging and I see that makeIndex () works:
mongoose.set('debug', true); Mongoose: myColl.ensureIndex({ type: 1 }) { safe: true, background: true } Mongoose: myColl.ensureIndex({ created: 1 }) { safe: true, background: true } Mongoose: myColl.ensureIndex({ updated: 1 }) { safe: true, background: true }
I also listened to errors:
mongoose.connection.on('error', function(err) { console.error('MongoDB error: %s', err); }); myCollModel.on('index',function(err) { console.error('MongoDB error: %s', err); });
I see my inserts and requests in the console, but without errors.
Any help would be greatly appreciated!
Thanks,
Nitzan bar
My schema is defined as follows:
myColl = new Schema(); myColl.add({ text : { type: String, required : true } , shortText: { type: String } , type : { type: String , index: true} , correctAnswerId : { type: ObjectId, ref: QuestionAnswer} , answers: { type: [ QuestionAnswer ] } });
In this case, the type index is not created. Note that sometimes after running makeIndexes () they are created a couple of times.
Thanks!