【问题标题】:Cannot nest $ under $in with decimal number in mongo query by using spring boot无法使用spring boot在mongo查询中将$嵌套在带有十进制数的$ in下
【发布时间】:2019-11-08 13:21:27
【问题描述】:

我们有一个在 robo mongo 中正确执行的 mongo 查询,用于查找 bigdecimal 值的列表,但我无法为其创建 java 代码。

我曾尝试通过使用 java 代码在 $in 运算符中使用 $numberDecimal,但它不起作用并出现此错误:

在 mongo 查询中,不能在 $in 下使用十进制数嵌套 $ 弹簧靴

所以我能够生成这种类型的查询,但它给了我错误:

db.getCollection("").aggregate({[
    "$match": {
        "$and" : [{ "xxx" : 
            {$in: [ {  "$numberDecimal" : "1235.000" 
} ] }} ]} ]})

这个正在工作:

db.getCollection("").aggregate({[
    "$match": {
        "$and" : [{ "xxx" : 
            {$in: [ {  NumberDecimal("1235.000" )
} ] }} ]} ]})

【问题讨论】:

    标签: java mongodb spring-boot


    【解决方案1】:

    当我们通过spring boot/java代码创建查询时,我们不需要做任何事情

    db.getCollection("").aggregate({[
        "$match": {
            "$and" : [{ "xxx" : 
                {$in: [ {  "$numberDecimal" : "1235.000" 
    } ] }} ]} ]})
    

    当查询到数据库时,类似查询工作。

    【讨论】:

    • 这节省了我很多时间。来点赞吧!
    猜你喜欢
    • 2020-01-08
    • 2020-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多