Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript MongoDB$geoNear和$match_Javascript_Node.js_Mongodb - Fatal编程技术网

Javascript MongoDB$geoNear和$match

Javascript MongoDB$geoNear和$match,javascript,node.js,mongodb,Javascript,Node.js,Mongodb,我的mongo DB中有200万行。当我尝试在下面生成代码时,需要50秒 const aggregateResult = await User.aggregate([ { $geoNear: { near: savedUser.location, distanceField: 'distance', spherical: true, }, }, { $m

我的mongo DB中有200万行。当我尝试在下面生成代码时,需要50秒

const aggregateResult = await User.aggregate([
    {
        $geoNear: {
            near: savedUser.location,
            distanceField: 'distance',
            spherical: true,
        },
    },
    {
        $match: {
            $and: [{ distance: { $gt: 0 } }, { vk_id: { $in: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] } }],
        },
    },
    {
        $project: {
            _id: 0,
            id: '$vk_id',
            distance: 1,
            updatedAt: 1,
            profileStatus: 1,
        },
    },
    {
        $limit: 100,
    },
]);
只有在将$match(带'vk_id')与$geoNear一起使用时,才会出现问题。 单独使用它没有任何长时间执行问题

索引就像屏幕截图上的索引一样