Let’s say I have 4 documents in the database:
{ name: 'alex' }
{ name: 'jen' }
{ name: 'alex' }
{ name: 'john'}
In MongoDB Shell, I want to know if 2 or more documents share the same ‘name’.
Basically, if all the names are different, return true.
If 2 or people have the same name, return false.
Try this, uses a quick map-reduce query to find the number of documents that have the same name, and returns true if they’re all different: