Let us say I've 4 documents within the database:

{ name: 'alex' }
{ name: 'jen' }
{ name: 'alex' }
{ name: 'john'}

In MongoDB Spend, I wish to determine if two or more documents share exactly the same 'name'.

Essentially, if all of the names will vary, return true. If 2 or people have a similar title, return false.

Do this, utilizes a quick map-reduce query to obtain the quantity of documents that have a similar title, and returns false if they are various different:

function allDifferent() {
    var m = function() { emit(this.name, 1); }
    var r = function(key, emits) {
        var n = 0; emits.forEach(function(v) { n += v; }); return n;
    }
    var result = db.mycol.mapReduce(m, r, { out: "namecounts" });
    var allDifferent= (db.namecounts.count( { value: { $gt: 1 } } ) == 0)
    db.namecounts.drop();
    return allDifferent;
}