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
2 Answers
Reset to default 5Perhaps 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.