在聚合框架示例中,有第一个和最后一个示例:
db.zipcodes.aggregate( { $group:
{ _id: { state: "$state", city: "$city" },
pop: { $sum: "$pop" } } },
{ $sort: { pop: 1 } },
{ $group:
{ _id : "$_id.state",
biggestCity: { $last: "$_id.city" },
biggestPop: { $last: "$pop" },
smallestCity: { $first: "$_id.city" },
smallestPop: { $first: "$pop" } } }
Run Code Online (Sandbox Code Playgroud)
我可以获得完整的zipcodes文档$first吗?
编辑:
为了澄清,我在我的快递应用程序中使用coffeescript执行以下操作,看起来很愚蠢:
@aggregate(
{
$group :
_id : "$category"
cnt : { $sum : 1 }
id: {$first: "$_id"}
name: {$first: …Run Code Online (Sandbox Code Playgroud)