Skip to content

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.


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);

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.

See also  Compare JSON objects ignoring the order of the properties in JavaScript

1 Comment »

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.