Php lumen和mongodb不工作的不同查询
我想得到唯一值的计数我的查询如下Php lumen和mongodb不工作的不同查询,php,mongodb,laravel,eloquent,Php,Mongodb,Laravel,Eloquent,我想得到唯一值的计数我的查询如下 $query = DB::connection('mongodb')->collection('email_message') ->distinct()->select("email_thread_id") ->where('email_account_id', (int)$request->email_account_id) ->
$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
它没有给我明确的价值。
有人能帮我解决吗
我在下面更新了我的mongodb屏幕截图,在这里我删除了一条记录,所以它将显示总共11条记录
注意:我刚才提到了distinct()上的字段名。“它的计数值应该是9,我得到的是12。”-这句话需要证明。如果你想说些什么,那么你需要为其他人提供说话的方式。这也确保了你没有真正弄错,错过了一些非常明显的东西。阅读链接,给人们一些他们可以复制的内容。
distinct()
中缺少字段
名称,这可能是导致错误结果的原因。它不起作用,它仍然给我12,而不是9,但我需要使用MongoDB的电子邮件线程id的不同值请检查您的DB记录,有12条不同的记录还是9条。它应该返回正确的distinct值。共有12条记录没有distinct值,其中distinct有9条records@hetalgohel你能发送一个带有字段名的记录的尖叫声吗?这样我就可以准确地理解这个问题了
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();