db.tempdata.insertMany([
{
name: "AAA",
age: 14,
country: "us"
},
{
name: "BBB",
age: 13,
country: "us"
},
{
name: "CCC",
age: 12,
country: null
},
{
name: "DDD",
age: 12,
country: null
}
])
db.tempdata.aggregate([{
$group: { _id: "$country",
all:{
$push: "$$ROOT"
}
}
}])
标签:name,mongodb,age,组内,分组,country,null
From: https://www.cnblogs.com/qiudaozhang/p/17266250.html