Mason
unread,Mar 8, 2012, 12:41:43 AM3/8/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongodb-user
I had online set to 'online' before, so I just use took it out and
used sort('online', 1) instead. Here is a bit more info
I ran the query in mongo shell. Below it got me a list of 20 results
order by online descending
PRIMARY> db.members.find({loc: {$near: {lat: 37.36883, lon:
-122.03635}, $maxDistance: 7.246376811594203}, sex: {$in: [2]}},
{online: 1, _id: 0, profile_id: 1}).sort({online: -1}).limit(20)
{ "online" : ISODate("2012-03-07T19:44:50.542Z"), "profile_id" :
203368 }
{ "online" : ISODate("2012-03-06T13:13:25.613Z"), "profile_id" :
1599080 }
{ "profile_id" : 1594412, "online" :
ISODate("2012-03-06T00:38:12.645Z") }
{ "profile_id" : 1578720, "online" :
ISODate("2012-03-06T00:18:04.414Z") }
{ "profile_id" : 1558740, "online" :
ISODate("2012-03-05T23:52:19.920Z") }
{ "profile_id" : 1469377, "online" :
ISODate("2012-03-05T21:57:23.946Z") }
{ "profile_id" : 1273984, "online" :
ISODate("2012-03-05T11:32:12.708Z") }
{ "profile_id" : 1199571, "online" :
ISODate("2012-03-05T06:25:16.338Z") }
{ "profile_id" : 1095081, "online" :
ISODate("2012-03-04T23:31:26.013Z") }
{ "profile_id" : 1037746, "online" :
ISODate("2012-03-04T19:45:16.794Z") }
{ "profile_id" : 649387, "online" :
ISODate("2012-03-03T19:06:11.979Z") }
{ "profile_id" : 524967, "online" :
ISODate("2012-03-03T11:30:17.664Z") }
{ "profile_id" : 511416, "online" :
ISODate("2012-03-03T10:40:51.435Z") }
{ "profile_id" : 511167, "online" :
ISODate("2012-03-03T10:39:53.159Z") }
{ "profile_id" : 510794, "online" :
ISODate("2012-03-03T10:38:32.797Z") }
{ "profile_id" : 480659, "online" :
ISODate("2012-03-03T08:47:41.846Z") }
{ "profile_id" : 444847, "online" :
ISODate("2012-03-03T06:32:47.830Z") }
{ "profile_id" : 420227, "online" :
ISODate("2012-03-03T05:03:22.089Z") }
{ "profile_id" : 350536, "online" :
ISODate("2012-03-03T00:54:25.091Z") }
{ "profile_id" : 217742, "online" :
ISODate("2012-03-02T16:59:22.217Z") }
And then, I ran the query again with .skip(5).limit(10) and got
PRIMARY> db.members.find({loc: {$near: {lat: 37.36883, lon:
-122.03635}, $maxDistance: 7.246376811594203}, sex: {$in: [2]}},
{online: 1, _id: 0, profile_id: 1}).sort({online:
-1}).skip(5).limit(10)
{ "profile_id" : 1199571, "online" :
ISODate("2012-03-05T06:25:16.338Z") }
{ "profile_id" : 1095081, "online" :
ISODate("2012-03-04T23:31:26.013Z") }
{ "profile_id" : 649387, "online" :
ISODate("2012-03-03T19:06:11.979Z") }
{ "profile_id" : 524967, "online" :
ISODate("2012-03-03T11:30:17.664Z") }
{ "profile_id" : 511416, "online" :
ISODate("2012-03-03T10:40:51.435Z") }
{ "profile_id" : 511167, "online" :
ISODate("2012-03-03T10:39:53.159Z") }
{ "profile_id" : 510794, "online" :
ISODate("2012-03-03T10:38:32.797Z") }
{ "profile_id" : 480659, "online" :
ISODate("2012-03-03T08:47:41.846Z") }
{ "profile_id" : 420227, "online" :
ISODate("2012-03-03T05:03:22.089Z") }
{ "profile_id" : 350536, "online" :
ISODate("2012-03-03T00:54:25.091Z") }
I expected it to skip the first 5 entires and return 10 entries start
from profile_id 1558740. However, it is not doing that. Also, of the
10 results returned, it skips 1037746 which is supposed to be the 3rd
entry returned from my list of 10