MongoDB 两个key之间值怎么比较?


  • 註冊用戶

    如下:

    amount1 >10 能返回查询结果,amount1>amount2 确不能,请问这里该怎样写?

    > db.pserson3.find()
    { "_id" : ObjectId("59096776f614bc28ee648600"), "amount1" : 20, "amount2" : 10 }
    { "_id" : ObjectId("59096789f614bc28ee648601"), "amount1" : 30, "amount2" : 20 }
    { "_id" : ObjectId("59096792f614bc28ee648602"), "amount1" : 10, "amount2" : 30 }
    > db.pserson3.find({"amount1":{$gt:10}})
    { "_id" : ObjectId("59096776f614bc28ee648600"), "amount1" : 20, "amount2" : 10 }
    { "_id" : ObjectId("59096789f614bc28ee648601"), "amount1" : 30, "amount2" : 20 }
    > db.pserson3.find({"amount1":{$gt:"amount2"}})

  • 註冊用戶

    db.pserson3.find("this.amount1 > this.amount2");


  • Lv 1

    @jesseshi

    db.pserson3.find({ $where :"this.amount1 > this.amount2"})


  • 註冊用戶

    db.pserson3.aggregate([
        {
            "$redact": {
                "$cond": [
                    { "$gt": [ "$amount1", "$amount2" ] },
                    "$$KEEP",
                    "$$PRUNE"
                ]
            }
        }
    ])


登录后回复
 

与 萌阔论坛 的连接断开,我们正在尝试重连,请耐心等待