【发布时间】:2017-04-13 20:20:17
【问题描述】:
我的 DB Mongoose 架构如下所示。
var blogSchema = mongoose.Schema({
blogText: { type: String},
location: {type: [Number]},
radius : {type: Number},
});
blogSchema.index({location: 2dsphere});
... .. .. ...
示例数据如下所示
{
"_id" : 58ef3f1919f99e3bb37ce21b,
"location" : [
77.706106,
12.9447252
],
"radius" : "4000",
"blogText" : "News 1 ....."},
{
"_id" : 58ef3f19b37ce21b19f99e3b,
"location" : [
77.709979,
12.9703882
],
"radius" : "1000",
"blogText" : "Health 1 ....."},
{
"_id" : 58ef3f1919f99e3bb37ce21b,
"location" :[
77.7060119,
12.9488936
],
"radius" : "3500",
"blogText" : "Lifestyle 1 ....."},
{
"_id" : 58ef3f1919f99e3bb37ce21b',
"location" : [
77.709979,
12.9703882
],
"radius" : "100",
"blogText" : "Sports....."},
{
"_id" : 58ef3f1919f99e3bb37ce21b',
"location" : [
77.706106,
12.9447252
],
"radius" : "800",
"blogText" : "Tech ....."}
我只需要获取那些在博客位置和半径下包含用户位置的博客。
我的查询看起来像。它根据请求的位置和半径获取数据。
db.blogs.find({location: {$geoNear: {$geometry: {type: "Point",coordinates: [77.706106,12.9447252]}$maxDistance: 500,$minDistance: 0}}}} })
提前致谢
【问题讨论】:
标签: mongodb geolocation geospatial