简体   繁体   English

lumen和mongodb的不同查询不起作用

[英]distinct query with lumen and mongodb not working

I want to get count of unique value my query is like below, 我想获取唯一值的计数,如下所示,

 $query = DB::connection('mongodb')->collection('email_message')
                ->distinct()->select("email_thread_id")
                ->where('email_account_id', (int)$request->email_account_id)
                ->where('status', "Active")->where('folder_id', "=", $folderId);
    $result = $query->count();

it's count value should be 9 and I am getting it as 12. 它的计数值应该是9,而我得到的是12。

it is not giving me distinct value. 它没有给我独特的价值。 can any one help me to resolve it out? 有人可以帮助我解决吗?

I have update my mongodb screen shot below, here I have deleted one record , so it will show total 11 records 我在下面更新了我的mongodb屏幕截图,在这里我删除了一条记录,因此它将显示总共11条记录 在此处输入图片说明

You didn't mention the distinct('FIELD_NAME') field name.

$query = DB::connection('mongodb')->collection('email_message')
            ->distinct('email_thread_id')->select("email_thread_id")
            ->where('email_account_id', (int)$request->email_account_id)
            ->where('status', "Active")->where('folder_id', "=", $folderId);
$result = $query->count();

NB:: I have just mention the field name over distinct() NB ::我刚刚在distinct()中提到了字段名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM