Mongoose schematype.castForQuery error. User authentication failed Mongoose schematype.castForQuery error. User authentication failed mongoose mongoose

Mongoose schematype.castForQuery error. User authentication failed


I found the solution to my question. Now it works. I had used the following code using Object.prototype....

    Object.prototype.getKey = function(value) {        for (var key in this) {            if (this[key] == value) {                return key;            }        }        return null;    };    var key = usernames.getKey(toUser);

It successfully returned the key of certain value (toUser in my case). However, everytime I logout of the system, it was not working and was not logging back in. Now I removed the entire method and replace with following code...

    function findKey(user) {        for (var key in usernames) {            if (usernames[key] == user) return key;        }        return false;    }    var key= findKey(toUser);

Which is simpler way to return key of cetrain value in JSON object. And Now, there is not a problem in my mongodb findOne method. Still couldnot figured out the reason behind the errors by using Object.prototype method to return key. However the strange error is gone with small changes.

SO, if you guys were stuck in same error type (Schematype.castForQuery is not a function ), it might be helpful

Thank you for your response though.