我是新的mongoDB用户,我只想将字符串字段值转换为(int,float或long)以便能够进行一些比较并将结果分配给新字段。
我无法忍受,我已经尝试了几个小时
这就是我想要做的事情:
// after doing $match and other projections and want to do last one $project
// P.S: $X values has been assigned in previous $project
{
$project:
{
xNumAsStr: "$X.NumAsStr",
xNum: NumberInt("$X.NumAsStr"),
result: NumberInt("$X.NumAsStr") > 2000 ? "SomeStr" : "AnotherStr"
}
}
当然,我所做的不正确,主要的想法是我想做一些计算和比较,我不知道它们,因为它们是动态的(由用户在UI中输入)。
有没有办法在SQL世界中这样做:
SELECT CASE
WHERE (some comparisons and math ops here) THEN 'ResultHere'
ELSE 'NoResult'
END
更新 有没有办法使用JS函数来做我想要的?