mongodb find duplicates in array across documents -


having array of emails on document. how find document in same collection shares @ least 1 email in common?

essentially have contacts collection , each contact document has array of emailaddresses[]. want make sure no 2 contact documents have email in common document, we're unable find happening.

db.collection.aggregate([ {"$unwind" : "$emails"}, {$group  : {"_id" : "$emails" , "count" :{"$sum" : 1} }}, {"$match" : {"count" : {"$gt" : 1}}} ]) 

this result emails dupicate


Comments

Popular posts from this blog

c - zlib and gdi32 with OpenSSL? -

java - inputmismatch exception -

ios - Align baselines with characters in large line heights with Text Kit -