我的文档结构:
{
"_id" : ObjectId("58a55f1a1f19ce1c0c436418"),
"Status" : false,
"Headers" : [
"Campaign Name",
"Ad Set Name",
"Ad Name",
"URL Tags",
"Bid Amount",
"Ad Set Daily Budget",
"Campaign Status",
"Ad Set Run Status",
"Ad Status",
"Campaign Objective",
"Buying Type",
"Ad Set Time Start",
"Use Accelerated Delivery",
"Link Object ID",
"Optimized Conversion Tracking Pixels",
"Optimized Event",
"Countries",
"Location Types",
"Gender",
"Age Min",
"Age Max",
"Custom Audiences",
"Excluded Custom Audiences",
"Flexible Inclusions",
"Targeting Optimization",
"Publisher Platforms",
"Facebook Positions",
"Device Platforms",
"Automatically Set Bid",
"Use Average Bid",
"Optimization Goal",
"Optimization Conversion Window (Days)",
"Billing Event",
"Story ID",
"Conversion Tracking Pixels",
"Creative Type",
"Instagram Account ID"
],
"CampaignId" : "Promoted | Kristin Filomena 2 | S:1176609245738008 | 02-14-2017 | 69",
"AdSetId" : 100.0,
"AdId" : "ACTIVE",
"Values" : [
"Remarketing | Facebook | Conversions | 02-14-2017",
"Cancelled Orders_Greater than 50%-Cancelled Orders_Less than 50% | Desktop | Feed | Female | 21-65",
"Promoted | Kristin Filomena 2 | S:1176609245738008 | 02-14-2017 | 69",
"utm_source=Facebook&utm_medium=social&utm_campaign=Remarketing | Facebook | Conversions | 02-14-2017&utm_term=Cancelled Orders_Greater than 50%-Cancelled Orders_Less than 50% | Desktop | Feed | Female | 21-65&utm_content=Promoted | Kristin Filomena 2 | S:1176609245738008 | 02-14-2017 | 69",
"100",
"50",
"PAUSED",
"ACTIVE",
"ACTIVE",
"Conversions",
"AUCTION",
"02/14/2017 19:02",
"No",
"o:147003252031951",
"tp:274128649620874",
"ADD_PAYMENT_INFO",
"US",
"home",
"Female",
"21",
"65",
"23842531891940746:Cancelled Orders_Greater than 50%, 23842531892040746:Cancelled Orders_Less than 50%",
"23842531887430746:Current Customers_All, 23842531979690746:Complete Registration - Last180Days",
"",
"none",
"Facebook",
"Feed",
"Desktop",
"No",
"No",
"OFFSITE_CONVERSIONS",
"1",
"IMPRESSIONS",
"s:1176609245738008",
"tp:274128649620874",
"Link Page Post Ad",
""
]
}
我的mongodb集合中有288个结构相似的文档。 我需要得到明确的字段campaignId,其中"值"数组包含 "再营销| Facebook |转换| 2017年2月14日"价值(可能是 Values数组的任何元素,现在我正在考虑第一个 一个)。
到目前为止,我所做的是,
db.adsets.aggregate([
{$match:{Values:"Lookalike | Facebook | Conversions | 02-14-2017"}},
{$project:{_id:0,Values: 1}},
{$unwind:"$Values"},
{$group:{_id:"$Values",count:{$sum:1}}},
{$project:{_id:0,Values:1,count:1}}
]);
答案 0 :(得分:1)
你可以尝试这样的事情。这将为您提供在Values
数组中至少有一个元素匹配条件的文档计数。
db.collection.count({Values:"Lookalike | Facebook | Conversions | 02-14-2017"}})
更新
db.collection.distinct("CampaignId", {Values:"Lookalike | Facebook | Conversions | 02-14-2017"}).length;