我们有 mongodb 集合
- 用户
{
_id: "1",
location: { coordinates: [ -63, 42 ], type: "Point" },
name: "user one"
},
{
_id: "2",
location: { coordinates: [ -83, 52 ], type: "Point" },
name: "user two"
}
{
_id: "3",
location: { coordinates: [ -53, 92 ], type: "Point" },
name: "user three"
}
- 用户连接
{
_id: "1",
connect1: "1", // ref: 'users'
connect2: "2" // ref: 'users'
},
{
_id: "2",
connect1: "1", // ref: 'users'
connect2: "3" // ref: 'users'
},
现在我们需要一个用户的所有连接。例如用户一 也有距离。所以结果会像
{
connect1: { user one details from users },
connect2: { user two details from users }.
distance: 10
},
{
connect1: { user one details from users },
connect2: { user three details from users }.
distance: 14
},
所以你能不能在这里帮助编写一个查询来使用 Mongodb $geonear 获取上面的数据。