我想获取唯一值的计数,如下所示,
$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();
它的计数值应该是9,而我得到的是12。
这并没有给我带来独特的价值。 有人可以帮我解决吗?
答案 0 :(得分:1)
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 ::我刚刚在distinct()上提到了字段名称