1

I have the following selection query, which should return the whole document based on user email an password input ( basically I am trying to make a login), result consols null. What´s wrong?

 user.loginUser = (jUserData, fCallback) => {
        var jUser = {
            userName: jUserData.txtEmailorPhoneNumber,
            password: jUserData.txtPassword
        }
        global.db.collection('users').findOne({ jUser }, (err, result) => {
            if (err) {
                var jError = { "status": "error", "message": "ERROR -> loginUser -> user.js -> 001" }
                return fCallback(false, jError)
            }
            var jOk = { "status": "ok", "message": "user.js -> user logged in -> 000" }
            console.log(JSON.stringify(result))
            return fCallback(false, jOk)
        })
    }

Users collection schema:

{
    "_id" : ObjectId("5a1a627f942bca5149ab3f25"),
    "userName" : "[email protected]",
    "firstName" : "A",
    "lastName" : "A",
    "password" : "1",
    "image" : "public/img_webshop/fileUserImage-1511678591824.png"
}
3
  • Can you post what is your jUserData? And also use findOne(jUser,(err, result)=>{..}) not findOne({jUser}, ()=>{}); Commented Nov 26, 2017 at 8:29
  • 1
    Try findOne(jUser, ...) and not findOne({ jUser }, ...) Commented Nov 26, 2017 at 8:30
  • Thank you @IdanDagan. Works now. That was the issue. Commented Nov 26, 2017 at 8:33

1 Answer 1

1

Try findOne(jUser, ...) instead of findOne({ jUser }, ...)

Sign up to request clarification or add additional context in comments.

Comments

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.