在使用聚合时,我想排除“ _id”字段并将其替换为“ action_id”字段。我必须在$ project中指定我不想排除的所有其他字段的问题。这是我的查询:
cursor = db.aggregate(
{
'$group': {
'_id': '$somefield',
'count': {'$sum': 1},
'average_latency': {'$avg': '$latency'}
}
},
{
'$project': {
'action_id': '$_id',
'_id': False,
'count': True,
'average_latency': True
}
}
如何避免写每个“字段”:$ project中为True?
答案 0 :(得分:1)
您可以使用$addFields
添加一个额外的字段,然后使用$project
删除Run
<TextBlock
TextWrapping ="Wrap" Height="33" FontSize="12"
Visibility="Visible"
TextAlignment="Center"
Foreground="#FFFFFF"
Opacity="0.5">
<Run Text="{Binding UnderLineMsg, Mode=OneWay}" />
<Hyperlink Name="PrivacyNoticeLink2" Command="{Binding OpenPrivacyNoticeCommand}">
<TextBlock
Visibility="Visible"
Name="privacyNoticeText2"
Text="{Binding PrivacyNoticeButtonLabel,FallbackValue='privacy notice' ,UpdateSourceTrigger=PropertyChanged}"/>
</Hyperlink>
</TextBlock>