与.every等价的猫鼬聚合

问题描述

我迷失了我的聚合过滤器。

我想根据他们的request._id重新整理访问者列表,并为其添加过滤器。

每个访客中都有一个units数组,每个访客中都有一个steps数组。

我正在搜索相当于array.every()而不是$ elemmatch的内容,以便在每个步骤中为一个单位查找true数据。

const aggregateFilters = { 'visitors.request.units': { $elemmatch: { label: unit,'workflow.steps': { $elemmatch: { role,'state.done': true } } } } }

如果我搜索一个state.done: false值,就可以了,因为即使其他值为true,我也想要结果。

但是当$ elemmatch作为.find()工作时,如果我只想要每个state.done: true的步骤,该如何过滤呢?

我不知道我是否清楚^^

谢谢!

解决方法

您可以翻转方法以获得所需的结果。您可以找到所有子文档中的 none 都为假

,而不是找到所有子文档都为真的地方
<canvas id="backgroundCanvas" style="position: absolute; z-index: 1; display: inline;" width="950" height="1600"></canvas>
    
    <div id="dmsInsWorkArea" class="dmsInsWorkArea">
       <iframe name="rightSide">...</iframe>
       <div name="leftSide" id="dmsInlineCommentsDiv" style="margin-left:70%;z-index: 10;">
          <div name="dmsCommentBox:45" style="border-radius: 11px; width: auto; z-index: 10; border: 1px solid grey;"></div>
          <div name="dmsCommentBox:46" style="border-radius: 11px; width: auto; z-index: 10; border: 1px solid grey;"></div>
       </div>
    </div>

我没有测试上面的代码,这是该方法可能工作方式的一个示例。

,

感谢您的回复,我已经尝试过了,但是它也可以作为.find()使用。如果state.done在Visitors数组中为true,则将其返回...

我终于找到了解决方法:

const aggregateFilters = { 'visitors.request.units': { $not: { $elemMatch: { label: unit,'workflow.steps': { $elemMatch: { role,'state.done': false } } } } } }