简单oracle 查询语句 转换为 mongo 查询语句

可以将简单的单表查询语句转换成Mongo过滤条件

列:

1、

SELECT score,person as name FROM demo WHERE  person like '%z' and score between 80 and 100
db.demo.aggregate([ 
        {"$match": {"$and": [{"person": {"$regex": "^.*z$", "$options": "i"}}, {"score": {"$gte": 80, "$lte": 100}}]}} ,
        {"$project": {"score": "$score", "name": "$person", "_id": 0}}
    ])

2、

SELECT * FROM demo WHERE score < 90 and person is not null or (score >= 90 and person <> 'zsa') or person in ('tyh','jhh')
db.demo.find( 
        {"$or": [{"$and": [{"score": {"$lt": 90}}, {"person": {"$exists": true}}]}, {"$and": [{"score": {"$gte": 90}}, {"person": {"$ne": "zsa"}}]}, {"person": {"$in": ["tyh", "jhh"]}}]}
    )

不支持函数(sum() ,count() ....) 、常数等式(1=1 或者 1!=2 ....)

依赖 druid 的 sql 解析

代码位置:码云

猜你喜欢

转载自www.cnblogs.com/zengsa/p/12291724.html
今日推荐