如何在mongoDB javascript中使用$ where

时间:2017-02-27 08:32:08

标签: mongodb meteor

我试图使用close $ where来获取mongoDB文档,但该函数返回我数据库中的第一个文档:

 scanCode: function (scannedcode) {
    try {

        let carItem = Cars.findOne({ $where: function () { return this.codeBarre == 'TOYOTA CAMRY      MC/ 2007CHASSIS/    509740' } });

        console.log(carItem)
        return carItem;
    }
    catch (e) {
        console.log(e.message)
    }

1 个答案:

答案 0 :(得分:2)

<强> EDITED

scanCode: function (scannedcode) {
try {

    let carItem = Cars.findOne({ $where: "this.codeBarre == 'TOYOTA CAMRY      MC/ 2007CHASSIS/    509740'" });

    console.log(carItem)
    return carItem;
}
catch (e) {
    console.log(e.message)
}