1

I'm trying to get a mongoDB document using close $where but the function return the first document in my database:

 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
  • You can also try Cars.findOne({ codeBarre: 'TOYOTA CAMRY MC/ 2007CHASSIS/ 509740' }); or Cars.find({ codeBarre: 'TOYOTA CAMRY MC/ 2007CHASSIS/ 509740' }).fetch(); Commented Feb 27, 2017 at 9:00

1 Answer 1

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)
}
Sign up to request clarification or add additional context in comments.

10 Comments

@sana so im guessing the logical expression your using is is wrong
i don't think so :/
can you explain your goal out of this query ?@sana
Cars.findOne({ $where: "this.codeBarre == 'TOYOTA CAMRY MC/ 2007CHASSIS/ 509740' "}); have you tried this method
how can i pass 'scannedcode' as un args insted of 'TOYOTA CAMRY MC/ 2007CHASSIS/ 509740' ??
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.