Node.js 使用geoSearch查询MongoDB失败,错误为“0”;can';“找不到ns”;

Node.js 使用geoSearch查询MongoDB失败,错误为“0”;can';“找不到ns”;,node.js,mongodb,mongoose,geojson,Node.js,Mongodb,Mongoose,Geojson,我正在试用MongoDB来存储简单的地理空间点数据(通常我会使用PostGIS)。我使用的是MongoDB v2.6,我通过Node.js和Mongoose(v3.8.22)访问它 我有一个测试模式,如下所示(基于中的模式,因为在MongoDB中设置的cannonical geojson模式的建议中似乎没有多少一致性,即使在文档中也是如此): 我使用虚拟数据填充集合: { pointType: 'Place', name: 'Little Snoring', comment: 'Bogus, D

我正在试用MongoDB来存储简单的地理空间点数据(通常我会使用PostGIS)。我使用的是MongoDB v2.6,我通过Node.js和Mongoose(v3.8.22)访问它

我有一个测试模式,如下所示(基于中的模式,因为在MongoDB中设置的cannonical geojson模式的建议中似乎没有多少一致性,即使在文档中也是如此):

我使用虚拟数据填充集合:

{ pointType: 'Place', name: 'Little Snoring', comment: 'Bogus, Dude!', geom: { type: 'Point', coordinates: [-20.0, 5.0] }},
{ pointType: 'Place', name: 'Fantasia Hollow', comment: 'Awesome!', geom: { type: 'Point', coordinates: [6.0, 10.0] }},
{ pointType: 'Place', name: "Lion's Den", comment: 'Growl-tastic', geom: { type: 'Point', coordinates: [34.0, -50.0] }},
{ pointType: 'Place', name: 'Dun Roamin', comment: 'So unoriginal', geom: { type: 'Point', coordinates: [-100.0, 70.0] }},
{ pointType: 'Sausage', name: 'Floodsville', comment: 'No way (sad face)', geom: { type: 'Point', coordinates: [38.0, 38.0] }}
…并通过Mongo客户端外壳查看它,这表明数据库已正确创建并具有索引。索引引用名称空间值为“ns:geojsonExample.places”(这是我所期望的)

在我的主文件中,我调用:

var places = require('../lib/places');  //import my schema
places.geoSearch({ 'pointType' : 'Place' }, { near : [-20.0, 5.0], maxDistance : 50 }, function (err, results, stats) {
    if (err) throw err;
    console.log('Result: ' + results);
});
geoSearch调用抛出以下消息:
MongoError:找不到ns

E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\base.js:246
        throw message;
              ^
MongoError: can't find ns
    at Object.toError (E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\utils.js:114:11)
    at E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1173:31
    at E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1882:9
    at Server.Base._callHandler (E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\base.js:453:41)
    at E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:487:18
    at MongoReply.parseBody (E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\responses\mongo_reply.js:68:5)
    at null.<anonymous> (E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:445:20)
    at emit (events.js:95:17)
    at null.<anonymous> (E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection_pool.js:201:1
3)
    at emit (events.js:98:17)
E:\MONGOOSE\u GEOJSON\node\u modules\MONGOOSE\node\u modules\mongodb\lib\mongodb\connection\base.js:246
抛出消息;
^
MongoError:找不到ns
在Object.toError(E:\MONGOOSE\u GEOJSON\node\u modules\MONGOOSE\node\u modules\mongodb\lib\mongodb\utils.js:114:11)
位于E:\MONGOOSE\u GEOJSON\node\u modules\MONGOOSE\node\u modules\mongodb\lib\mongodb\db.js:1173:31
位于E:\MONGOOSE\u GEOJSON\node\u modules\MONGOOSE\node\u modules\mongodb\lib\mongodb\db.js:1882:9
在Server.Base.\u callHandler(E:\MONGOOSE\u GEOJSON\node\u modules\MONGOOSE\node\u modules\mongodb\lib\mongodb\connection\Base.js:453:41)
位于E:\MONGOOSE\u GEOJSON\node\u modules\MONGOOSE\node\u modules\mongodb\lib\mongodb\connection\server.js:487:18
在MongoReply.parseBody(E:\MONGOOSE\u GEOJSON\node\u modules\MONGOOSE\node\u modules\mongodb\lib\mongodb\responses\mongo\u reply.js:68:5)
在空。(E:\MONGOOSE\u GEOJSON\node\u modules\MONGOOSE\node\u modules\mongodb\lib\mongodb\connection\server.js:445:20)
在发出时(events.js:95:17)
在空。(E:\MONGOOSE\u GEOJSON\node\u modules\MONGOOSE\node\u modules\mongodb\lib\mongodb\connection\connection\u pool.js:201:1
3)
在发出时(events.js:98:17)

我不知道如何解决这个问题,因为我可以看到索引中正确存储的ns值。我的地理搜索请求是否有误,或者是否有猫鼬“抓住了”我需要知道?非常感谢

当我测试它时,它对我很好。验证
places
是否符合您的预期。您将geohaystack索引与平面上的点一起使用
[x,y]
,而不是使用GeoJSON。您确定不需要2dsphere索引吗?谢谢您的查看。我将问题追溯到节点环境中的异步数据加载和索引。因此,如果我用async.each包装虚拟数据加载,问题就会消失。显然,您可以使用geoHaystack和geoJSON(不需要在球坐标中)。然而,2dsphere实际上会给我更大的灵活性。
E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\base.js:246
        throw message;
              ^
MongoError: can't find ns
    at Object.toError (E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\utils.js:114:11)
    at E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1173:31
    at E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1882:9
    at Server.Base._callHandler (E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\base.js:453:41)
    at E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:487:18
    at MongoReply.parseBody (E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\responses\mongo_reply.js:68:5)
    at null.<anonymous> (E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:445:20)
    at emit (events.js:95:17)
    at null.<anonymous> (E:\MONGOOSE_GEOJSON\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection_pool.js:201:1
3)
    at emit (events.js:98:17)