compare 2 different documents in mongodb by common field code example
Example: mongodb find documents where two fields are equal
db.myCollection.find( { $where: "this.a1.a != this.a2.a" } )
db.myCollection.find( { $where: "this.a1.a != this.a2.a" } )