I have a Spring entity which looks like:
@Document(
collection = "users"
)
public class UserEntity extends BaseEntity {
@Indexed
private String msisdn;
...
}
In the mongo shell, I'm able to find the duplicate msisdn
fields via:
db.users.aggregate([
{"$group": { "_id": "$msisdn", "count": { "$sum": 1 } } },
{"$match": {"_id":{ "$ne": null } , "count": {"$gt": 1} } },
{"$project": {"msisdn": "$_id", "_id": 0} }
]);
Which returns for example:
[
{ msisdn: '123456' },
{ msisdn: 'ABCDEF' }
]
My question is: how can I convert this aggregation to Spring?