Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Mongoose无法对位置数组执行$near查询_Node.js_Mongodb_Mongoose_Geolocation - Fatal编程技术网

Node.js Mongoose无法对位置数组执行$near查询

Node.js Mongoose无法对位置数组执行$near查询,node.js,mongodb,mongoose,geolocation,Node.js,Mongodb,Mongoose,Geolocation,我曾尝试寻找解决方案,并阅读了$near和$geoNear查询的部分文档,但没有成功 var userSchema = new Schema({ zipcode : { formatted : {type : String, required : false, default : ""}, geo : { type: [Number], default: [0,0]} // long, lat } }); userSchema.index({"zipcode.geo" :

我曾尝试寻找解决方案,并阅读了$near和$geoNear查询的部分文档,但没有成功

var userSchema = new Schema({
  zipcode : {
    formatted : {type : String, required : false, default : ""},
    geo : { type: [Number], default: [0,0]} // long, lat
  }
});
userSchema.index({"zipcode.geo" : '2d'});
在另一个文件上

var locationSchema = new Schema({
  formatted : {type : String, unique : false, required : true},
  geo : { type: [Number], default: [0,0]}
});

locationSchema.index({geo: '2d'});

var storeSchema = new Schema({
  locations : [locationSchema],
});
在我的控制器上

let nearQuery = {
  $near : [ user.zipcode.geo[0], user.zipcode.geo[1]],
  spherical: true,
  $maxDistance: 7000
}
Stores.find(locations : nearQuery).exec(function(error, doc) {

});
但我最终得到了一个错误——“错误:不能将球形数组与数组一起使用。”

当我移除

spherical : true
我收到错误-“planner返回错误:无法找到$geoNear查询的索引”

我知道我做错了什么,我就是想不出怎么解决它。我怎样才能解决这个问题?或者最好的方法是什么


提前感谢。

结果表明,我对查询使用了错误的语法,并试图在locations字段上运行查询,而我本应在locations.geo字段上运行查询