You could use $where
:
db.myCollection.find( { $where: "this.a1.a != this.a2.a" } )
However, be aware that this won't be very fast, because it will have to spin up the java script engine and iterate each and every document and check the condition for each.
If you need to do this query for large collections, or very often, it's best to introduce a denormalized flag, like areEqual
. Still, such low-selectivity fields don't yield good index performance, because he candidate set is still large.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…