Sunday, 19 March 2017

Sorting in monk not sorting correctly

I've written an app that leverages mongodb for storing some documents, and I'm trying to sort by the date field. When I run the query directly in the mongo shell it works perfectly fine, however it completely goes to shit in monk.

VisitsCollection.find({
            "visitor.attachments.approved.dateSigned": {
                $gte: new Date(d) // d is 6 months back
            }
        }, {sort: { "date": -1 }, limit: 30, skip: page * offset })

^ That's the sorting code I'm using.

Returned dates from monk (formatted in frontend, sorry bout that):

Mar 2, 2017
Mar 16, 2017
Mar 12, 2017
Mar 12, 2017
Mar 12, 2017
Mar 9, 2017
Mar 9, 2017
Mar 8, 2017
Mar 8, 2017
Mar 6, 2017
Mar 6, 2017
Mar 6, 2017
Mar 4, 2017
Mar 3, 2017
Mar 3, 2017
Mar 14, 2017

And this is the result in mongo:

> db.visits.find({}, {"date": 1}).sort({date: -1});
{ "_id" : ObjectId("58ceec2dbc29845efd24e135"), "date" : ISODate("2017-03-25T18:35:17.171Z") }
{ "_id" : ObjectId("58ca7742fab5a11864228231"), "date" : ISODate("2017-03-15T23:32:42.020Z") }
{ "_id" : ObjectId("58ca7742fab5a11864228503"), "date" : ISODate("2017-03-15T17:58:23.336Z") }
{ "_id" : ObjectId("58ca7742fab5a118642283c2"), "date" : ISODate("2017-03-15T12:33:53.917Z") }
{ "_id" : ObjectId("58ca7742fab5a118642281c7"), "date" : ISODate("2017-03-15T09:07:51.754Z") }
{ "_id" : ObjectId("58ca7742fab5a11864228280"), "date" : ISODate("2017-03-15T08:25:19.475Z") }
{ "_id" : ObjectId("58ca7742fab5a1186422827f"), "date" : ISODate("2017-03-15T07:52:34.506Z") }
{ "_id" : ObjectId("58ca7742fab5a11864228587"), "date" : ISODate("2017-03-15T00:56:43.998Z") }
{ "_id" : ObjectId("58ca7742fab5a1186422847d"), "date" : ISODate("2017-03-14T14:10:34.946Z") }
{ "_id" : ObjectId("58ca7742fab5a11864228499"), "date" : ISODate("2017-03-14T02:08:02.714Z") }
{ "_id" : ObjectId("58ca7742fab5a11864228351"), "date" : ISODate("2017-03-14T01:44:17.546Z") }
{ "_id" : ObjectId("58ca7742fab5a118642283e9"), "date" : ISODate("2017-03-14T00:44:02.844Z") }
{ "_id" : ObjectId("58ca7742fab5a118642284c5"), "date" : ISODate("2017-03-12T23:26:23.182Z") }
{ "_id" : ObjectId("58ca7742fab5a1186422835f"), "date" : ISODate("2017-03-12T19:21:59.451Z") }
{ "_id" : ObjectId("58ca7742fab5a118642284a9"), "date" : ISODate("2017-03-12T08:04:17.950Z") }
{ "_id" : ObjectId("58ca7742fab5a118642282bd"), "date" : ISODate("2017-03-12T05:28:20.945Z") }
{ "_id" : ObjectId("58ca7742fab5a1186422842c"), "date" : ISODate("2017-03-12T02:26:53.589Z") }
{ "_id" : ObjectId("58ca7742fab5a1186422838e"), "date" : ISODate("2017-03-12T00:02:53.632Z") }
{ "_id" : ObjectId("58ca7742fab5a118642282ba"), "date" : ISODate("2017-03-11T11:27:44.405Z") }
{ "_id" : ObjectId("58ca7742fab5a118642283f3"), "date" : ISODate("2017-03-11T09:22:47.131Z") }



via yusijs

No comments:

Post a Comment