2016-09-22 105 views
0

注意:我通过在PC上执行代码添加了屏幕截图。我已经看到了这个多次,但我无法解释这至少对自己在MongoDB中,解决方法是什么?

this MongoDB $unwind for nodejs11:10分钟教程 - 喇叭说:

这个查询:

 

db.companies.aggregate([ 
    { $match: {"funding_rounds.investments.financial_org.permalink": "greylock" } }, 
    { $project: { 
     _id: 0, 
     name: 1, 
     amount: "$funding_rounds.raised_amount", 
     year: "$funding_rounds.funded_year" 
    } } 
]) 
 

产生具有数量和年份数组的文档。

documents that have arrays for both amount and year

因为我们所访问的升高量和资助的一年,轮筹资阵列中的每个元素。 为了解决这个问题,我们可以对这个聚合管道我们的项目阶段之前退绕阶段,并说我们要unwind资金轮阵列参数如下:

 

db.companies.aggregate([ 
    { $match: {"funding_rounds.investments.financial_org.permalink": "greylock" } }, 
    { $unwind: "$funding_rounds" }, 
    { $project: { 
     _id: 0, 
     name: 1, 
     amount: "$funding_rounds.raised_amount", 
     year: "$funding_rounds.funded_year" 
    } } 
]) 
 

unwind has the effect of outputting to the next stage more documents than it receives as input

unwind具有输出到下一个阶段的多于其接收的文档作为输入的效果。

我的困惑:

  • 什么问题扬声器在1点21分分钟指什么?
  • 什么修复他指的是?

回答

0

问题是我们需要一个[公司,金额,年份]每个集合的单个文档,其中数量和年份都只有一个标量值。正如讲座中所解释的,我们拥有的输入具有数组,而$ unwind将这些输入转换为单个值。

这个讲座并没有给出一个具体的问题,这个问题试图解决,但让我建议这样做:“给我一份报告,显示Greylock每年投入多少资金,然后给我一个每年的报告显示出资公司的资金,按提供的金额订购。“如果您考虑如何使用汇总框架生成这些数据,您可以看到这些报告将需要演讲中所示的一组文档。

相关问题