I'm writing a deduplication script in mongo but they return mobile numbers that are equal to null
or an empty string, thinking those are all duplicates. I've tried to play around with $ne
in mongo but can't quite get it to work. Does anyone know how to return all duplicates that mobile number is not equal to null
or an empty string?
$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,
]
);
});
Thanks in advance!