距开课0天0时0分-10200799秒
为情所困2017-04-27 09:02:02 0 2 278
[MongoDB讨论组]举报回复话题 ↕
查询所有 x > y 的所有 name
2
0
分享
给我你的怀抱 2017-04-27 09:04:022楼
db.collections.find({'$where': "this.x > this.y"}, {'name': 1})
赞 +0添加回复
迷茫 2017-04-27 09:04:021楼
这样还能按照x y 的差值排序
db.collection.aggregate( [ { $project : { _id: '$name', val: { $subtract : [ "$x", "$y" ] }, x: '$x', y: '$y' } }, {$match: {val: {$gt: 0}}}, {$sort: { val: -1 }} ] )
给我你的怀抱 2017-04-27 09:04:022楼
赞 +0添加回复
迷茫 2017-04-27 09:04:021楼
这样还能按照x y 的差值排序
赞 +0添加回复