查找非空mongodb的重复项

查找非空mongodb的重复项,mongodb,Mongodb,我正在用mongo编写一个重复数据消除脚本,但它们返回的手机号码等于null或空字符串,认为这些都是重复的。我曾尝试在mongo中使用$ne,但无法完全实现。有人知道如何返回手机号码不等于null或空字符串的所有副本吗 $mobile_duplicates = User::raw(function ($collection) { return $collection->aggregate( [ [

我正在用mongo编写一个重复数据消除脚本,但它们返回的手机号码等于
null
或空字符串,认为这些都是重复的。我曾尝试在mongo中使用
$ne
,但无法完全实现。有人知道如何返回手机号码不等于
null
或空字符串的所有副本吗

    $mobile_duplicates = User::raw(function ($collection) {
        return $collection->aggregate(
            [
                [
                    '$limit' => 200000,
                ],
                [
                    '$group' => [
                        '_id' => [
                            'mobile', //=> '$mobile',
                        ],
                        'uniqueIds' => [
                            '$addToSet' => '$_id',
                        ],
                        'count' => [
                            '$sum' => 1,
                        ],
                    ],
                ],
                [
                    '$match' => [
                        // '_id' => [
                        //    '$ne' => "",
                        // ],
                        // '_id' => [
                        //    '$ne' => null,
                        // ],
                        'count' => [
                            '$gt' => 1,
                        ],
                    ],
                ]
            ],
            [
                'allowDiskUse' => true,
            ]
        );
    });

提前谢谢

在这篇文章中找到了答案!stackoverflow.com/questions/14184099/…(将$match查询分为两个不同的查询-这对我来说很有用:

$mobile_duplicates = User::raw(function ($collection) {
        return $collection->aggregate(
            [
                [
                    '$match' => [
                        'mobile' => [
                            '$ne' => '',
                            '$exists' => true,
                        ],
                    ],
                ],
                [
                    '$group' => [
                        '_id' => [
                            'mobile' => '$mobile',
                        ],
                        'uniqueIds' => [
                            '$addToSet' => '$_id',
                        ],
                        'count' => [
                            '$sum' => 1,
                        ],
                    ],
                ],
                [
                    '$match' => [
                        'count' => [
                            '$gt' => 1,
                        ],
                    ],
                ],
            ],
            [
                'allowDiskUse' => true,
            ]
        );
    });

请使用问题上的“编辑”链接添加其他信息。“发布答案”按钮应仅用于问题的完整答案。-这是完整答案!我正在等待在时间限制后用绿色按钮标记它。只需从链接中删除你的答案。因为如果链接被删除,你的答案不会被删除对其他人有用。重复,而不是回答重复,但是感谢指示,所以总是感谢OP试图解决这些问题。