[{ name: 'xxxx', A:12, B:23 }, { name:'xxxxx', A:10, B:8 } ]
我想查出 B 比 A 大 的document . 怎么写。没有,在mysql 最常用了 select * from table where B > A , 到了mongodb 就无法做到??
google
stackoverflow
google都不会,怎么混
使用$where可以实现
https://docs.mongodb.com/manual/reference/operator/query/
@yuezm 只能是 A: {$gt : 23}, 不能写 A:{$gt:B}
@manyuewuxin 只能是 A: {$gt : 23}, 不能写 A:{$gt:B}
@mrlong 可以啊,这样写
db.demos.find( { $where:function(){ return this.A < this.B } } )
@mrlong collections.aggregate([{$match: { $expr: { $gt: [ “$B”, “$A” ] } }}]).toArray();
这是原生驱动库写法,mongoose我没用不清楚。
@manyuewuxin 3.6 才支持$expr 我是3.2版本,怎么办???
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
google
stackoverflow
google都不会,怎么混
使用$where可以实现
https://docs.mongodb.com/manual/reference/operator/query/
@yuezm 只能是 A: {$gt : 23}, 不能写 A:{$gt:B}
@manyuewuxin 只能是 A: {$gt : 23}, 不能写 A:{$gt:B}
@mrlong 可以啊,这样写
@mrlong collections.aggregate([{$match: { $expr: { $gt: [ “$B”, “$A” ] } }}]).toArray();
这是原生驱动库写法,mongoose我没用不清楚。
@manyuewuxin 3.6 才支持$expr 我是3.2版本,怎么办???