0

I have a Mongoose model like

const OffersSchema = new Schema({ 
    storeIdList : [{
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Stores',
        required: true
    }],
    status: {
        type: String, 
        required: true, 
        enum: ['INACTIVE', 'ACTIVE', 'SUSPENDED'],
        default: 'INACTIVE'
    }
   // ...some other fields...
})
OffersSchema.index({"storeIdList":1,"status":1,"_id":-1})

And later I'm querying:

let index = {"storeIdList":1,"status":1,"_id":-1}
let docs = await Offers.find({}).hint(index)

And I'm getting an error "planner returned error: bad hint". What am I doing wrong?

João Otero
  • 948
  • 1
  • 15
  • 30
  • could it be that my enum field is indeed an array, and then one can not have 2 multikey fields in a single index? reference: https://docs.mongodb.com/manual/core/index-multikey/ – João Otero Mar 04 '19 at 21:27
  • Yes. .As per MongoDB, You cannot create a compound multikey index if more than one to-be-indexed field of a document is an array. – Mani Mar 04 '19 at 21:31
  • my doubt is if my `status` field considered as an array or a string... isn't it a string? – João Otero Mar 04 '19 at 21:42
  • It will be a string. Do you have any other information on the error message other than "planner returned error: bad hint" – Mani Mar 04 '19 at 21:51
  • no, that's the only information – João Otero Mar 04 '19 at 21:56
  • Can you try running the same query from mongo shell? – Mani Mar 04 '19 at 22:10
  • I've found the problem: when I was testing, I changed the index... However, I hadn't cleaned up the previously built indexes. And because of that, my "new index" was not being found, giving the `bad hint` error. It seems the indexes are not re-created automatically... I had to drop the database and built them again. – João Otero Mar 04 '19 at 22:29

0 Answers0