云开发 数据库能实现字段运算后作为条件查询吗,如 where A*15 > 300 ?
发布于 6 年前 作者 nfu 4164 次浏览 来自 官方Issues

类似的情况…单字段运算,或者多字段运算…文档好像没找到类似的?

2 回复

可以的,A > B

const $ = db.command.aggregate

db.collection(‘table2’).aggregate()

.addFields({

    matched: $.gt([’$A’, ‘$B’])

})

.match({

    matched:!0

})

.end().then(res => console.log(res))

.catch(err => console.error(err))

=================

A*B > 300

db.collection(‘table2’).aggregate()

.addFields({

    matched: $.gt([$.multiply([’$A’, ‘$B’]), 300])

})

.match({

    matched:!0

})

.end().then(res => console.log(res))

.catch(err => console.error(err))

==============

多个数或字段值相乘

$.multiply([’$A’, ‘$B’, 10,…])

https://image.wxopen.club/content_3a677664-4f48-11ea-9248-001a7dda7111.png

还有很多运算api,自己每个都点一下,看看是什么意思,以后需要的时候,就知道有没有什么api可以使用了

.where({

    A: _.expr($.gt([_.mul(15), 300]))

})

回到顶部