MongoDB : querying documents with two equal fields, $match and $eq
问题 What is the best way to return all documents in a collection if I want document.a == document.b? I've tried db.collection.aggregate([ { $match: { $eq: [ '$a', '$b' ] } }]) But it returns with no errors or results, because I assume it is literally matching strings "$a" and "$b". Is there a different way to specify that these are fields? db.collection.aggregate([ { $project: { eq: { $cond: [ { $eq: [ '$a', '$b' ] }, 1, 0 ] } } }, { $match: { eq: 1 } }]) The above works, but requires the