[SERVER-19471] mongodb geonear sort by distance and time Created: 17/Jul/15  Updated: 23/Nov/15  Resolved: 17/Jul/15

Status: Closed
Project: Core Server
Component/s: Geo
Affects Version/s: 3.0.4
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: derek Assignee: Sam Kleinman (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

data in db follows:

{ "_id" : ObjectId("55a8c1ba3996c909184d7a22"), "uid" : "1db82e8a-2038-4818-b805-76a46ba62639", "createdate" : ISODate("2015-07-17T08:50:02.892Z"), "palce" : "aa", "sex" : 1, "longdis" : 1, "location" : [ 106.607312, 29.575281 ] }
{ "_id" : ObjectId("55a8c1ba3996c909184d7a24"), "uid" : "1db82e8a-2038-4818-b805-76a46ba62639", "createdate" : ISODate("2015-07-17T08:50:02.920Z"), "palce" : "bbb", "sex" : 1, "longdis" : 1, "location" : [ 106.589896, 29.545098 ] }
{ "_id" : ObjectId("55a8c1ba3996c909184d7a25"), "uid" : "1db82e8a-2038-4818-b805-76a46ba62639", "createdate" : ISODate("2015-07-17T08:50:02.922Z"), "palce" : "ccc", "sex" : 1, "longdis" : 1, "location" : [ 106.590758, 29.566713 ] }
{ "_id" : ObjectId("55a8c1ba3996c909184d7a26"), "uid" : "1db82e8a-2038-4818-b805-76a46ba62639", "createdate" : ISODate("2015-07-17T08:50:02.923Z"), "palce" : "ddd", "sex" : 1, "longdis" : 1, "location" : [ 106.637039, 29.561436 ] }
{ "_id" : ObjectId("55a8c1bc3996c909184d7a27"), "uid" : "1db82e8a-2038-4818-b805-76a46ba62639", "createdate" : ISODate("2015-07-17T08:50:04.499Z"), "palce" : "eee", "sex" : 1, "longdis" : 1, "location" : [ 106.539522, 29.57929 ] }
{ "_id" : ObjectId("55a8d12e78292fa3837ebae4"), "uid" : "1db82e8a-2038-4818-b805-76a46ba62639", "createdate" : ISODate("2015-07-17T09:55:58.947Z"), "palce" : "fff", "sex" : 1, "longdis" : 1, "location" : [ 106.637039, 29.561436 ] }

I want to first of all, sort by the distance, if the distance is the same, sort by the time.

my command :

db.runCommand( { geoNear: "paging", near: [106.606033,29.575897 ], spherical : true,maxDistance : 1/6371, minDistance:0/6371,distanceMultiplier: 6371,num:2,query: {'_id': {'$nin': []}} })

or

db.paging.find({'location':{$nearSphere: [106.606033,29.575897], $maxDistance:1}}).limit(5).skip((2 - 1) * 2).sort({createdate:-1})

Which two commands can not meet the requirements, how to solve this problem, please?



 Comments   
Comment by Sam Kleinman (Inactive) [ 17/Jul/15 ]

Thanks for this report. See the documentation for combining sorts with near queries, for more information on these kinds of operations.

Regards,
sam

Comment by derek [ 17/Jul/15 ]

ref to : http://stackoverflow.com/questions/31475277/geonear-sort-by-distance-and-time?answertab=active#tab-top

Generated at Thu Feb 08 03:51:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.