【发布时间】:2018-10-28 12:04:31
【问题描述】:
我在 Laravel 5.6 中使用 Moloquent 模型。以下是我的收藏记录:-
{
"_id" : ObjectId("5afe619dbe0b8d0e5876b16b"),
"name" : "Central Park",
"categories" : [
"4d4b7105d754a06376d81259",
"4bf58dd8d48988d116941735",
"4bf58dd8d48988d119941735",
"4d4b7105d754a06376d81259",
"4bf58dd8d48988d116941735",
"4bf58dd8d48988d119941735",
"4d4b7105d754a06374d81259",
"4bf58dd8d48988d16d941735"
],
"loc" : {
"type" : "Point",
"coordinates" : [
88.4166612820784,
22.5835157504658
]
}
}
我从 Laravel 控制器运行这个查询。
$users = MongoTest::where('loc', 'near', [
'$geometry' => [
'type' => 'Point',
'coordinates' => [
$longitude,
$latitude,
],
],
'$maxDistance' => 10,
])->get();
print_r($users);
我收到此错误:-
error processing query: ns=tkit.testTree: GEONEAR field=loc maxdist=10 isNearSphere=0
Sort: {}
Proj: {}
planner returned error: unable to find index for $geoNear query
我该如何解决这个问题?
【问题讨论】:
-
当然是通过创建地理空间索引。该错误告诉您您没有索引,
"loc"字段上需要有一个索引。 -
你能建议怎么做吗,我的意思是结构?我是 MongoDB 新手
标签: php mongodb laravel moloquent