mongoose地理空间查询不检索任何文档
我试图在mongodb集合上使用mongoose地理空间查询。 “2dsphere”索引已应用于位置对象。请在下面找到查询:
const data = await Banks.find(
{
location: {
$near: {
$geometry: {
type: "Point",
coordinates: [73.8567, 18.5204]
},
$maxDistance: 10000000
}
}
}
);
console.log('-- the data --', data);
许多文档中的一个如下所示:
{
"_id" : ObjectId("5c64511a04ede20c28f6ef0b"),
"location" : {
"coordinates" : [
92.747338,
11.675442
],
"type" : "Point"
},
"name" : "Test name",
}
我试图将最大距离设置得尽可能大。但查询不会检索任何文档。可能是什么问题呢 ?
回答如下:上面提到的查询工作正常。我一直指的是错误的型号名称(集合)。集合名称是银行,我一直称为银行。模型名称在MongoDB中区分大小写。
mongoose地理空间查询不检索任何文档
我试图在mongodb集合上使用mongoose地理空间查询。 “2dsphere”索引已应用于位置对象。请在下面找到查询:
const data = await Banks.find(
{
location: {
$near: {
$geometry: {
type: "Point",
coordinates: [73.8567, 18.5204]
},
$maxDistance: 10000000
}
}
}
);
console.log('-- the data --', data);
许多文档中的一个如下所示:
{
"_id" : ObjectId("5c64511a04ede20c28f6ef0b"),
"location" : {
"coordinates" : [
92.747338,
11.675442
],
"type" : "Point"
},
"name" : "Test name",
}
我试图将最大距离设置得尽可能大。但查询不会检索任何文档。可能是什么问题呢 ?
回答如下:上面提到的查询工作正常。我一直指的是错误的型号名称(集合)。集合名称是银行,我一直称为银行。模型名称在MongoDB中区分大小写。