我认为我错过了MongoDB Aggregate Pipeline知识的一个关键部分,以便接近我想要做的事情。
这是我的数据:
[
{frameId: <some unique guid>, videoSessionId: 1, subject: "John", "createdBy": "personA", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 1, subject: "John", "createdBy": "personA", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 1, subject: "John", "createdBy": "personA", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 2, subject: "John", "createdBy": "personA", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 3, subject: "John", "createdBy": "personB", "blurry": true},
{frameId: <some unique guid>, videoSessionId: 3, subject: "John", "createdBy": "personB", "blurry": true},
{frameId: <some unique guid>, videoSessionId: 3, subject: "John", "createdBy": "personB", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 3, subject: "John", "createdBy": "personB", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 4, subject: "Mary", "createdBy": "personB", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 4, subject: "Mary", "createdBy": "personB", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 5, subject: "Mary", "createdBy": "personB", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 5, subject: "Mary", "createdBy": "personB", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 6, subject: "Mary", "createdBy": "personB", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 6, subject: "Mary", "createdBy": "personB", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 7, subject: "Mary", "createdBy": "personB", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 7, subject: "Mary", "createdBy": "personB", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 7, subject: "Mary", "createdBy": "personB", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 7, subject: "Mary", "createdBy": "personB", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 7, subject: "Mary", "createdBy": "personB", "blurry": false},
]
我想查询数据并收到:
[
{frameId: <some unique guid>, videoSessionId: 3, subject: "John", "createdBy": "personB", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 3, subject: "John", "createdBy": "personB", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 4, subject: "Mary", "createdBy": "personB", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 4, subject: "Mary", "createdBy": "personB", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 5, subject: "Mary", "createdBy": "personB", "blurry": false},
{frameId: <some unique guid>, videoSessionId: 5, subject: "Mary", "createdBy": "personB", "blurry": false},
]
这是我想要的明文版本:
&#34;在personB创建的所有非模糊帧中,每个主题给我最多2个videoSessions。&#34;
更深一点:
我目前正在解决这个问题,使用以下方法。这对我来说似乎效率低下,因为它需要查找,展开,替换root和另一个匹配。