mongodb $where 查询中的坑

mongodb 查询中坑就是数字开头的字段不能用点号,只能用[""]。例如:

即:db.datas.find({$where:"this['54bcfc6c329af61034f7c2fc'].testRet !== this['54bcfc6c329af61034f7c2fc'].taskRet"})

但是  如果你用

 

即:db.datas.find({$where:"this.54bcfc6c329af61034f7c2fc.testRet !== this.54bcfc6c329af61034f7c2fc.taskRet"})

查询时会报错

Error: error: { "ok" : 0, "errmsg" : "Failed to call method", "code" : 1 }

 mongodb $where 的用法详见mongodb官网:

                     https://docs.mongodb.com/manual/reference/operator/query/where/

原文地址:https://www.cnblogs.com/Kellana/p/5804389.html