最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - meteor, minimongo not sorting on date properly, even with ISO8601 data format - Stack Overflow

programmeradmin2浏览0评论

Problem

I have this page on my meteor site: twbrewing/blog and on it I want to sort the blog posts by date.

If I do the following in the console:

BlogPosts.find({}, {sort: {date: -1, time: -1}})

It returns the posts in the wrong order. Which is also confirmed by the incorrect display order of the posts.

The date of the first doc returned in the collection is:

date: "2013-12-16"

while the date of the second post is:

date: "2014-01-02"

I believe this is proper ISO 8601 format so I am not really sure why its failing.

Additional code

I do publish from the server:

Meteor.publish 'blogPosts', () ->
    BlogPosts.find({}, {sort: {date: -1, time: -1}})

Subscribe in the iron-router data method:

# Blog
  @route 'blog',
    path: '/blog/'
    waitOn: ->
      Meteor.subscribe 'blogPosts'
    data: ->
      blogPosts: BlogPosts.find({}, {sort: {date: -1, time: -1}})

Problem

I have this page on my meteor site: twbrewing./blog and on it I want to sort the blog posts by date.

If I do the following in the console:

BlogPosts.find({}, {sort: {date: -1, time: -1}})

It returns the posts in the wrong order. Which is also confirmed by the incorrect display order of the posts.

The date of the first doc returned in the collection is:

date: "2013-12-16"

while the date of the second post is:

date: "2014-01-02"

I believe this is proper ISO 8601 format so I am not really sure why its failing.

Additional code

I do publish from the server:

Meteor.publish 'blogPosts', () ->
    BlogPosts.find({}, {sort: {date: -1, time: -1}})

Subscribe in the iron-router data method:

# Blog
  @route 'blog',
    path: '/blog/'
    waitOn: ->
      Meteor.subscribe 'blogPosts'
    data: ->
      blogPosts: BlogPosts.find({}, {sort: {date: -1, time: -1}})
Share Improve this question edited Jan 14, 2014 at 2:25 funkyeah asked Jan 13, 2014 at 16:31 funkyeahfunkyeah 3,1946 gold badges33 silver badges48 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Perhaps you're missing the sort specifier?

BlogPosts.find({}, {sort: {date: -1, time: -1}})

I wish I could change the title of this post to "noob question about Cursors and un-reproduced sort failure".

My blog posts were returning incorrectly but that was a code error:

BlogPosts.find({}, {date: -1, time: -1})

instead of:

BlogPosts.find({},sort:{ {date: -1, time: -1}})

then after fixing the code, a redeployment suggested the problem had not resolved itself. I attempted to debug in the console with my misunderstanding of how a cursor should return... e.g. that they are supposed to return unordered was a surprise to me as a newbie (I didn't understand DDP and/or maybe mongo enough... although I don't recall seeing it in the Meteor or mongo docs that I have read).

A database reset and a second redeployment fixed whatever issue had been persisting. So I think I would contribute it user error.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论