Unsupported projection option: sort – Mongoose error – How to fix?
UnhandledPromiseRejectionWarning: MongoError: Unsupported projection option: sort is an error that is thrown when you pass sort options into mongoose schema methods.
Advertisements
I passed the sort and limit options inside the mongoose find method as a parameter which turned out to be wrong.
ProductSchema.statics = { filter (query, options){ return this.find(query, options); } }
Advertisements
Mongoose provides chainable methods with find that can be used for sort and limit.
let latestProduct = await productModel.filter({}).sort({ "date": -1 }).limit(1);
Unsupported projection option: sort — This error implies sort and limit are not valid options that you can pass inside mongoose find method.
1 Comment »