rovan-a of Pixel's Programmer
1/12/2017 - 2:05 PM

Alternatif data model untuk managix report

Alternatif data model untuk managix report

// Ambil report untuk ad_id 6062174737093, breakdown berdasarkan age
db.getCollection('report_breakdown').find({ ad_id: '6062174737093', breakdownKey: 'age'})

// Ambil report untuk ad_id 6062174737093, breakdown berdasarkan gender
db.getCollection('report_breakdown').find({ ad_id: '6062174737093', breakdownKey: 'gender'})

// Ambil report untuk ad_id 6062174737093, breakdown berdasarkan age
db.getCollection('report_breakdown').find({ ad_id: '6062174737093', breakdownKey: 'region'})


// RESPONSe

/* 1 */
{
    "_id" : ObjectId("58787e83db8ea716cd0da6d4"),
    "report_id" : "0000001",
    "account_id" : "268694267",
    "campaign_id" : "6062174166693",
    "adset_id" : "6062174483093",
    "ad_id" : "6062174737093",
    "date" : "2016-12-15",
    "column" : "reach",
    "breakdownKey" : "region",
    "breakdownName" : "aceh",
    "value" : 100
}

/* 2 */
{
    "_id" : ObjectId("58787e83db8ea716cd0da6d6"),
    "report_id" : "0000001",
    "account_id" : "268694267",
    "campaign_id" : "6062174166693",
    "adset_id" : "6062174483093",
    "ad_id" : "6062174737093",
    "date" : "2016-12-15",
    "column" : "reach",
    "breakdownKey" : "region",
    "breakdownName" : "bali",
    "value" : 100
}

/* 3 */
{
    "_id" : ObjectId("58787e83db8ea716cd0da6d8"),
    "report_id" : "0000001",
    "account_id" : "268694267",
    "campaign_id" : "6062174166693",
    "adset_id" : "6062174483093",
    "ad_id" : "6062174737093",
    "date" : "2016-12-15",
    "column" : "reach",
    "breakdownKey" : "region",
    "breakdownName" : "bandung",
    "value" : 100
}
{
    "report_id" : "0000001",
    "account_id" : "268694267",
    "campaign_id" : "6062174166693",
    "adset_id" : "6062174483093",
    "ad_id" : "6062174737093",
    "date" : "2016-12-15",
    "column" : "reach",
    "breakdownKey" : "gender",
    "breakdownName" : "female",
    "value" : 100
}

{
    "report_id" : "0000001",
    "account_id" : "268694267",
    "campaign_id" : "6062174166693",
    "adset_id" : "6062174483093",
    "ad_id" : "6062174737093",
    "date" : "2016-12-15",
    "column" : "reach",
    "breakdownKey" : "gender",
    "breakdownName" : "male",
    "value" : 100
}

{
    "report_id" : "0000001",
    "account_id" : "268694267",
    "campaign_id" : "6062174166693",
    "adset_id" : "6062174483093",
    "ad_id" : "6062174737093",
    "date" : "2016-12-15",
    "column" : "reach",
    "breakdownKey" : "platform",
    "breakdownName" : "facebook",
    "value" : 100
}

{
    "report_id" : "0000001",
    "account_id" : "268694267",
    "campaign_id" : "6062174166693",
    "adset_id" : "6062174483093",
    "ad_id" : "6062174737093",
    "date" : "2016-12-15",
    "column" : "reach",
    "breakdownKey" : "platform",
    "breakdownName" : "instagram",
    "value" : 100
}

{
    "report_id" : "0000001",
    "account_id" : "268694267",
    "campaign_id" : "6062174166693",
    "adset_id" : "6062174483093",
    "ad_id" : "6062174737093",
    "date" : "2016-12-15",
    "column" : "reach",
    "breakdownKey" : "platform",
    "breakdownName" : "audience_network",
    "value" : 100
}

{
    "report_id" : "0000001",
    "account_id" : "268694267",
    "campaign_id" : "6062174166693",
    "adset_id" : "6062174483093",
    "ad_id" : "6062174737093",
    "date" : "2016-12-15",
    "column" : "reach",
    "breakdownKey" : "region",
    "breakdownName" : "aceh",
    "value" : 100
}

// -- Main report & breakdown dipisah collection
// -- Breakdown disimpan semua dalam 1 level tanpa stacking, tapi ditambah field "column" & "breakdownKey" untuk keperluan sorting



/* 1 */
{
    "report_id" : "0000001",
    "account_id" : "268694267",
    "campaign_id" : "6062174166693",
    "adset_id" : "6062174483093",
    "ad_id" : "6062174737093",
    "date" : "2016-12-15",
    "clicks" : "5",
    "reach" : "2441",
    "impressions" : "2447"
}

/* 2 */
{
    "report_id" : "0000002",
    "account_id" : "268694267",
    "campaign_id" : "6062174166693",
    "adset_id" : "6062174483093",
    "ad_id" : "6062174737093",
    "date" : "2016-12-16",
    "clicks" : "10",
    "reach" : "2435",
    "impressions" : "4547"
}

/* 3 */
{
    "report_id" : "0000003",
    "account_id" : "268694267",
    "campaign_id" : "6062174166693",
    "adset_id" : "6062174483093",
    "ad_id" : "6062174737093",
    "date" : "2016-12-17",
    "clicks" : "100",
    "reach" : "243",
    "impressions" : "45"
}