Mongoose not creating index Mongoose not creating index mongoose mongoose

Mongoose not creating index


When defining a field that's an ObjectId reference to a document in another collection, the ref attribute's value is the string name of the model, not the model itself. So it should look like this instead:

correctAnswerId : { type: ObjectId, ref: 'QuestionAnswer' }

I have a feeling that the timing of that failure is impacting whether the type index is created or not.


Indeed, I had the same problem.

And then I copy the ensureindex debug info into mongo terminal to try it out, the command was sent (just as shown from mongoose console), but the creation is failed due to the problem of mongo:

{    "err" : "ns name too long, max size is 128",    "code" : 10080,    "n" : 0,    "connectionId" : 78,    "ok" : 1}

then I give the option {name: 'super_index'}, then it is done.

Hope it is helpful for you!