我正在尝试mongodb
使用$within
运算符进行地理空间查询。我有一个包含位置字段的集合条目:
location: {
bounds: {
south_west: { lat: XX.XXXXXX, lng: XX.XXXXX },
north_east: { lat: XX.XXXXXX, lng: XX.XXXXX }
},
center: {
lat: XX.XXXXXX,
lng: XX.XXXXXX
}
}
对于我的查询,我想获取所有位于对象location.center
范围内的位置google.maps
。我有这样的事情:
query = {}
var southWest = map.getBounds().getSouthWest();
southWest = [southWest.lat(), southWest.lng()];
var northEast = map.getBounds().getNorthEast();
northEast = [northEast.lat(), northEast.lng()];
query["location.center"] = { $within: { $box: [southWest, northEast] } }
但我一直得到
Exception from Meteor.flush: Error: Unrecognized key in selector: $within
at Error (<anonymous>)
at Function.LocalCollection._exprForConstraint (http://localhost:3000/packages/minimongo/selector.js?2373a18a9a4640513e41d7850f17f62f76b7c589:559:11)
at Function.LocalCollection._exprForOperatorTest (http://localhost:3000/packages/minimongo/selector.js?2373a18a9a4640513e41d7850f17f62f76b7c589:468:36)
at Function.LocalCollection._exprForKeypathPredicate (http://localhost:3000/packages/minimongo/selector.js?2373a18a9a4640513e41d7850f17f62f76b7c589:387:34)
at Function.LocalCollection._exprForSelector (http://localhost:3000/packages/minimongo/selector.js?2373a18a9a4640513e41d7850f17f62f76b7c589:307:36)
at Function.LocalCollection._compileSelector (http://localhost:3000/packages/minimongo/selector.js?2373a18a9a4640513e41d7850f17f62f76b7c589:284:24)
at new LocalCollection.Cursor (http://localhost:3000/packages/minimongo/minimongo.js?7f5131f0f3d86c8269a6e6db0e2467e28eff6422:71:39)
at LocalCollection.find (http://localhost:3000/packages/minimongo/minimongo.js?7f5131f0f3d86c8269a6e6db0e2467e28eff6422:57:10)
at _.extend.find (http://localhost:3000/packages/mongo-livedata/collection.js?3ef9efcb8726ddf54f58384b2d8f226aaec8fd53:155:34)
at Template.feed.feed_items (http://localhost:3000/client/modules/js/feed.js?5ed30ddbd861944b636dbe03c13cc80421258a5b:129:17)
而且我不确定如何进行。通过一个简单的 JSON.stringify(query) 我注意到查询的结果就像
{"location.center":{"$within":{"$box":[[39.93623526127148,-75.63687337060549],[39.984129247435064,-75.57438862939455]]}}}
无论如何我可以防止引号被环绕$within
和$box
选择器?我相信这就是我的异常被抛出的地方。