node.js mongojs findOne callback returning error as null

前端 未结 1 1405
温柔的废话
温柔的废话 2020-12-19 10:55

Presently being driven up the wall by this error.

I am running a node.js app with the mongojs wrapper for mongodb. I Started mongod on the default port, then ran

1条回答
  •  温柔的废话
    2020-12-19 11:26

    When the findOne query doesn't find at least one matching document, the second parameter of the callback (in this case user) is set to null. It's not an error, so err is also null. So what you're seeing is the expected no-match-found response.

    Update

    Note that findOne has been deprecated in the 2.0 driver, but its replacement also exhibits this same behavior:

    users.find({'fb_id' : fbUserMetadata.id}).limit(1).next(err, doc) {
        // doc is null if a matching document wasn't found
    });
    

    0 讨论(0)
提交回复
热议问题