MongDB原生查询经典示例

1.一个成功的多条件复杂查询:

参考连接:https://blog.csdn.net/leinminna/article/details/89817410

{
    "$and":[
        {
            "$and":[
                {
                    "$and":[
                        {
                            "data.供应商状态.value":"启用"
                        }
                    ]
                }
            ],
            "form_id":NumberLong("1169503914198962176"),
            "tenant_id":NumberLong("1168765585752985600"),
            "status":{
                "$ne":"DELETED"
            }
        },
        {
            "$or":[
                {
                    "creator":NumberLong("1161928622353813504")
                },
                {
                    "creator":{
                        "$ne":NumberLong("1161928622353813504")
                    },
                    "status":{
                        "$nin":[
                            "DELETED",
                            "APPROVAL_CREATE",
                            "DRAFT"
                        ]
                    }
                }
            ]
        }
    ]
}

2.踩过的坑

“form_id”:NumberLong(“1169503914198962176”),OK,没有问题;
“form_id”:{“numberLong”:“1169503914198962176”},不行,这样查询不出结果,还不会报错,坑啊!
“form_id”:{"$numberLong":“1169503914198962176”},直接报错

3.关于in

sql需要拼接的条件是creator in ids;

        "creator":{
           "$in":[
              NumberLong("1161928622353813504"),
              NumberLong("1161928622353813504"),
              NumberLong("1161928622353813504")
           ]
       }

测式结果:
ids == null; // 直接报错;
ids.size() == 0; // 查出的数据位0条;

你可能感兴趣的:(mongoDB,java技术,编码)