Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8190745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:44:38+00:00 2026-06-07T03:44:38+00:00

Sorting doesnt work with Mongoose, but I don’t understand how this can be possible

  • 0

Sorting doesnt work with Mongoose, but I don’t understand how this can be possible since I’ve searched so much! Any time I tried it didn’t work. Here is my code

Pics.find({}).limit(8).populate('creator').sort("created_at", 1).execFind(function(err, docs){
    console.log(docs);
});

I get:

TypeError: Invalid sort() argument. Must be a string or object.
at Query.sort (/Users/n/Proj/feetshot/node_modules/mongoose/lib/query.js:755:11)
at /Users/n/Proj/feetshot/app.js:112:45
at callbacks (/Users/n/Proj/feetshot/node_modules/express/lib/router/index.js:272:11)
at param (/Users/n/Proj/feetshot/node_modules/express/lib/router/index.js:246:11)
at pass (/Users/n/Proj/feetshot/node_modules/express/lib/router/index.js:253:5)
at Router._dispatch (/Users/n/Proj/feetshot/node_modules/express/lib/router/index.js:280:4)
at Object.handle (/Users/n/Proj/feetshot/node_modules/express/lib/router/index.js:45:10)
at Context.next (/Users/n/Proj/feetshot/node_modules/express/node_modules/connect/lib/http.js:204:15)
at Context.<anonymous> (/Users/n/Proj/feetshot/node_modules/passport/lib/passport/context/http/actions.js:64:8)
at SessionStrategy.pass (native)

How can I make sort working?

Here is my schema:

var PicSchema = new Schema({
creator: { type: Schema.ObjectId, ref: 'Users' }
, body: String
, created_at: { type: Date, default: Date.now }
, link: { type: String, index: { unique: true } }
, twitter_id: { type: String, index: { unique: true } }
, tags: [String]
  , likes: [{ type: Schema.ObjectId, ref: 'Users' }]
   });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:44:39+00:00Added an answer on June 7, 2026 at 3:44 am

    Based on your error message you must be using Mongoose 3.x, however you’re using the 2.x sort method parameter style. Either switch to the 2.7.0 Mongoose release or change your sort usage to sort('created_at'). From the 3.x source:

    /**
    * sort
    *
    * Sets the sort order. Accepts a single parameter, either an object or string.
    * If an object is passed values allowed are 'asc', 'desc', 'ascending', 'descending', 1, -1.
    * If a string is passed it must be a space delimited list of path names. The sort order of each path is ascending unless the path name is prefixed with `-` which will be treated as descending.
    *
    * Examples:
    *
    * // these are equivalent
    * query.sort({ field: 'asc', test: -1 });
    * query.sort('field -test');
    *
    * @param {Object|String}
    * @api public
    */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this code should work like merge sort algorithm but it doesnt work and gives
My code below seems logical however i don't know why the sorting doesn't work
EDIT: Solved this myself - obviously won't work as sorting the dataTable doesn't sort
i feel like this is a stupid question but i can't find anything anywhere.
can't get sorting working for a django-tables2 table. class MyModel(models.Model): pid = models.AutoField('id',primary_key =
I using jquery sorting ( http://jqueryui.com/demos/sortable/ ). Is it possible to sort (move list)
I am using JS sorting to call this method: def sort params[:piece].each_with_index do |id,
I'm sorting a NSMutableArray that has NSString that contain numbers. This is the code
Possible Duplicate: Sorting an IList in C# I have an IList<Keyword> where Keyword is
Has anyone managed to extend a GridView with default sorting? This seems pretty trivial

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.