Created
September 17, 2013 10:08
-
-
Save kejyun/6592427 to your computer and use it in GitHub Desktop.
MongoDB LBS查詢範例 : 找捷運台北車站附近距離2公里內的捷運站、依照建立時間做排序、找前3筆資料(子查詢)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var query = db.lbs_test.find({loc: {$near:[25.046084,121.517542] , $maxDistance:2/111.12 }}).sort({time:1}); | |
query.limit(3).forEach(printjson); | |
// 查詢結果 | |
{ | |
"_id" : ObjectId("5238179cdfba7ac818bb5fcd"), | |
"name" : "捷運臺大醫院站", | |
"loc" : { | |
"lat" : 25.041535, | |
"long" : 121.516029 | |
}, | |
"time" : 11 | |
} | |
{ | |
"_id" : ObjectId("5238179cdfba7ac818bb5fd2"), | |
"name" : "捷運中山站", | |
"loc" : { | |
"lat" : 25.052596, | |
"long" : 121.520327 | |
}, | |
"time" : 16 | |
} | |
{ | |
"_id" : ObjectId("5238179cdfba7ac818bb5fd3"), | |
"name" : "捷運雙連站", | |
"loc" : { | |
"lat" : 25.057961, | |
"long" : 121.520842 | |
}, | |
"time" : 17 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment