Mongodb 比较两个字段的比率
Mongodb Compare two fields with ratio
字段是其他字段两倍的行
举例说明:
{id : 1 , price : 10 , spent : 5}
{id : 1 , price : 20 , spent : 30}
{id : 1 , price : 40 , spent : 90}
{id : 1 , price : 80 , spent : 200}
我想要花费等于或大于价格两倍的行(花费 >= 2*价格)
结果:
{id : 1 , price : 40 , spent : 90}
==> (花费 >= 2价格) [90>80]*
{id : 1 , price : 80 , spent : 200}
==> (花费 >= 2价格) [160>200]*
请参考建议,除了使用 $where
我的 mongo 集群有使用限制 $where
(MongoError: $where is not allowed in this atlas tier)
字段是其他字段两倍的行 举例说明:
{id : 1 , price : 10 , spent : 5}
{id : 1 , price : 20 , spent : 30}
{id : 1 , price : 40 , spent : 90}
{id : 1 , price : 80 , spent : 200}
我想要花费等于或大于价格两倍的行(花费 >= 2*价格)
结果:
{id : 1 , price : 40 , spent : 90}
==> (花费 >= 2价格) [90>80]*
{id : 1 , price : 80 , spent : 200}
==> (花费 >= 2价格) [160>200]*
请参考建议,除了使用 $where
我的 mongo 集群有使用限制 $where
(MongoError: $where is not allowed in this atlas tier)