我有以下格式的数据
{
"result" : [
{
"advertiser" : "lordandtaylor"
,
"networks" : [
"Pepperjam"
],
"publishers" : [
"best-price.com",
"allthingswholesale.com"
]
}]
}
现在我想以下面的格式显示它
{"advertiser":"lordandtaylor" , "networks":"1" , "publishers":"2"}
答案 0 :(得分:1)
我得到了解决方案
db.link.aggregate([
{
{
$project : { _id: 0, advertiser : "$_id.advertiser", networks : {$size : "$networks"} , advertisers : {$size : "$publishers"} }
}
]);