I have this page on my meteor site: twbrewing.com/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.
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}})
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With