聚合函数返回错误的查询长度

时间:2019-03-26 16:29:04

标签: mongodb

我的汇总函数有问题,该函数返回错误的结果长度。我有2个集合,“客户”和“朋友”,“客户”集合具有地理位置坐标和其他重要信息,如用户名和密码等...,在“朋友”集合中,我存储客户朋友。我有此功能,可以很好地解决一个问题,它返回错误的长度结果。

mongo.clients.aggregate([{
  $geoNear: {
    near: {
      type: "Point",
      coordinates: data.coordinates
    },
    maxDistance: 20000,
    distanceField: "location"
  }
}, {
  $project: options.options.projection
}, {
  $skip: 0
}, {
  $limit: 10
}, {
  $lookup: {
    from: "friends",
    localField: "_id",
    foreignField: "friend_id",
    as: "friends"
  }
}, {
  $match: {
    $and: [{
      "friends.cust_id": {
        $nin: [ObjectID('5c86d093dea6161c0871ac34')],
      }
    }, {
      "friends.friend_id": {
        $nin: ["$_id"],
      },
    }]
  }
}])

因此,要了解我在这里做什么,我将使用“ John”名称作为示例。 约翰有4个朋友,约翰想在他的位置附近找到更多朋友。当我尝试从“客户”集合中寻找John的新朋友时,我想从结果中排除他现有的朋友,并让他获得10个与他接近的新客户,但是当我运行我的职能时,我只有6个客户从结果中得出结果,但不是10。在排除他的4个当前朋友之后,如何保持10个的限制? 谢谢

0 个答案:

没有答案