[英]How to retrieve document using geospatial query in Mongoose
我正在嘗試在 mongodb 集合上使用貓鼬地理空間查詢。 “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 中區分大小寫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.