查询所有 x > y 的所有 name
db.collections.find({'$where': "this.x > this.y"}, {'name': 1})
This way, you can also sort by the difference between x and y
db.collection.aggregate( [ { $project : { _id: '$name', val: { $subtract : [ "$x", "$y" ] }, x: '$x', y: '$y' } }, {$match: {val: {$gt: 0}}}, {$sort: { val: -1 }} ] )
This way, you can also sort by the difference between x and y