是否有方法跳过/绕过Mongodb聚合阶段

是否有方法跳过/绕过Mongodb聚合阶段,mongodb,aggregation-framework,Mongodb,Aggregation Framework,我对MongoDB查询有问题。我对MongoDB数据库的查询是: Places.aggregate([ Stage-A { "$geoNear": { "near": { "type": "Point", "coordinates": coord }, "spherical": true, "maxDistance" : maxDistance, "quer

我对MongoDB查询有问题。我对MongoDB数据库的查询是:

    Places.aggregate([
      Stage-A
      { "$geoNear": {
        "near": {
        "type": "Point",
        "coordinates": coord
      },
        "spherical": true,
        "maxDistance" : maxDistance,
        "query": {tags:{$all:tags}},
        "limit": resultLimit,
        "distanceField": "distance"
      }
    },
    {Stage-B = check is stage-A have found any documents},
    {Stage-C},
    {Stage-D}
  ])
我想检查stage-A是否找到任何结果,如果没有,我想用不同的查询转到stage-C。如果阶段A找到结果,那么我将直接转到最后的阶段D。我假设的聚合查询如下所示:

Places.aggregate([
    Stage-A
   { 
     "$geoNear": {
       "near": {
       "type": "Point",
       "coordinates": coord
     },
       "spherical": true,
       "maxDistance" : maxDistance,
       "query": {tags:{$all:tags}},
       "limit": resultLimit,
       "distanceField": "distance"
     }
    },
    Stage-B
    {
      In this stage-B, I want to check if the stage-A has found any results,
      if results, I want to move to the last stage-D, otherwise stage-C         then finally Stage-D
    },
    Stage-C
    {
      "$geoNear": {
        "near": {
        "type": "Point",
        "coordinates": coord
      },
        "spherical": true,
        "maxDistance" : maxDistance,
        "query": {tags:{$in:tags}}, >> different query
        "limit": resultLimit,
        "distanceField": "distance"
      }
    },
    Stage-D
    {
      $project:{

      }
    }
])

我想知道这种逻辑流在MongoDB聚合或其他方面是否可行。如果是这样,B阶段是什么?如果没有,解决这个问题的最佳方法是什么?我想在一个请求中完成所有这些操作,这样可以节省一些CPU周期。

您确定有可能使用另一个$geoNear操作符来实现Stage C吗?医生说是的,我看过文件了。这意味着,我们没有任何解决问题的替代方案。您确定有可能使用另一个$geoNear操作符进行阶段C吗?医生说是的,我看过文件了。这意味着,我们没有任何其他解决问题的办法。