如何使用$ geoNear,$ lookup和$ match在Mongoose Aggregation Operators中获取Near Location?

时间:2017-10-09 07:54:47

标签: node.js mongodb mongoose mongodb-query aggregation-framework

你可以帮我解决这个问题,我尝试使用namaKota(城市名称)和Lat,Long参数搜索附近的位置。这是我的代码

 var namaKota = "Malang";
 var coords = [];
    coords[0] =lat;
    coords[1] =long;

 VehiclesDB.aggregate([
            {
                $geoNear: {
                    geoNear: "rentaldbs",
                    near: coords,
                }
            },
            {
                $lookup:
                    {
                        from: "rentaldbs",
                        localField: "mitraId",
                        foreignField: "_id",
                        as: "mitra"
                    }}
            ,
            {
                $unwind: "$mitra"
            },{

                $match: {
                    "mitra.namaKota": namaKota
                }
            }

和我的结果一样

Couldn't find any Vehicles with idMalang

0 个答案:

没有答案