Meteor.js: Find all documents and return in reverse natural order

前端 未结 4 743
栀梦
栀梦 2021-01-05 05:10

I am trying to return all documents in a collection, to use it with an {{#each}} in my template. My code looks like this:

return Answers.find({}, {sort: {$nat

4条回答
  •  一生所求
    2021-01-05 05:27

    I think you might be confusing definitions of 'natural order' here. One the one hand there is a natural sort order for letters/strings (A,B,C...) and numbers (1,2,3...).

    But in the case of mongo, 'natural' refers to the order the data was written to disk. '{$natural:1}' returns 'documents in the order they exist on disk...' and, so '{$natural:-1}' reverses that (http://docs.mongodb.org/manual/reference/operator/meta/natural/).

    So without the code that writes the data and some insight into how it was written to disk, we cannot test your hypothesis that it is not working correctly.

提交回复
热议问题