gpt4 book ai didi

php - Sum 在 php mongodb 中不起作用

转载 作者:可可西里 更新时间:2023-11-01 10:48:54 24 4
gpt4 key购买 nike

下面是我的mongodb数据,

{
"_id" : ObjectId("598be687c54bba05596e347e"),
"slotid" : "248x300x250xnewdiv",
"request_id" : "07f811ee-a8e3-4d76-9390-49f613f6bb86",
"zoneid" : "248",
"bidder" : "rubicon",
"cpm" : 0.6,
"width" : NumberInt("300"),
"height" : NumberInt("250"),
"is_win" : NumberInt("1"),
"is_fail" : NumberInt("0"),
"reponsetime" : NumberInt("294"),
"requestdate" : "2017-08-10 04:52:25",
"responsedate" : "2017-08-10 04:52:26"
},
{
"_id" : ObjectId("598be687c54bba05596e3480"),
"slotid" : "248x300x250xnewdiv",
"request_id" : "07f811ee-a8e3-4d76-9390-49f613f6bb86",
"zoneid" : "247",
"bidder" : "rubicon",
"cpm" : 0.6,
"width" : NumberInt("468"),
"height" : NumberInt("60"),
"is_win" : NumberInt("1"),
"is_fail" : NumberInt("0"),
"reponsetime" : NumberInt("299"),
"requestdate" : "2017-08-10 04:52:25",
"responsedate" : "2017-08-10 04:52:26"
}

我需要使用 php 从 mongodb 获取数据,下面是我的 php 代码

 $res = array(
array(
'$group' => array(
"_id" => array("slotid" => '$slotid',"bidder" => '$bidder'),"total" => array('$sum' => '$cpm'),
),
),
);
$db = (new MongoDB\Client)->database;
$resbids = $db->responsebids->aggregate($res);
foreach($resbids as $res)
{
print_r($res);

}

我需要按 slotid 和 bidder 以及 cpm value 进行分组,该组工作正常但 cpm 始终显示为零,这段代码有什么问题?下面是我的示例结果,

MongoDB\Model\BSONDocument Object
(
[storage:ArrayObject:private] => Array
(
[_id] => MongoDB\Model\BSONDocument Object
(
[storage:ArrayObject:private] => Array
(
[slotid] => 248x300x250xnewdiv
[bidder] => rubicon
)

)

[total] => 0
)

)

感谢任何帮助....

最佳答案

您的每千次展示费用为 float 值,您无法通过 $sum 添加 float 值

关于php - Sum 在 php mongodb 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45605376/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com