KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Let's say I have some Schema which has a virtual field like this var schema = new mongoose.Schema( { name: { type: String } }, { toObject: { virtuals: true }, toJSON: { virtuals: true } }); schema.virtual("name_length").get(function(){ return this.name.length; }); In a query is it possible to sort the results by the virtual field? Something like schema.find().sort("name_length").limit(5).exec(function(docs){ ... }); When I try this, the results are simple not sorted...
Tags (comma-separated)
Save Edits
Cancel