Cordon Davies
Cordon Davies

Reputation: 211

MongoError: Incorrect arguments

Suddenly got this error in my log-in function and I can't figure out exactly what is causing it. I checked both cases where I use query or insert into MongoDB, but can't see any problems with the arguments. Just using json in the first argument, and a callback function in the second, which I think should work and seems to work in other cases where I use it. I think I may have syntax error(maybe) or something that might be causing it. Any ideas?
First Mongo usage:

this.validateLogin = function(username, password, callback){
    "use strict";
    users.findOne({'_id' :username }, function (err,user){
        //some code
    });
}

Second Mongo usage:

sessions.insert(session, function (err, result) {
        "use strict";
        callback(err, session_id);
    });

Here is the Error:

C:\...\node_modules\mongodb\lib\mongodb\connection\b
ase.js:242
        throw message;
              ^
MongoError: Incorrect arguments
    at Object.toError (C:\...\node_modules\mongodb\l
ib\mongodb\utils.js:110:11)
    at Server.Base._callHandler (C:\...\node_modules
\mongodb\lib\mongodb\connection\base.js:444:65)
    at C:\...\node_modules\mongodb\lib\mongodb\conne
ction\server.js:485:18
    at MongoReply.parseBody (C:\...\node_modules\mon
godb\lib\mongodb\responses\mongo_reply.js:68:5)
    at null.<anonymous> (C:\...\node_modules\mongodb
\lib\mongodb\connection\server.js:443:20)
    at EventEmitter.emit (events.js:95:17)
    at null.<anonymous> (C:\...\node_modules\mongodb
\lib\mongodb\connection\connection_pool.js:191:13)
    at EventEmitter.emit (events.js:98:17)
    at Socket.<anonymous> (C:\...\node_modules\mongo
db\lib\mongodb\connection\connection.js:418:22)
    at Socket.EventEmitter.emit (events.js:95:17)

Thanks in advance!

Upvotes: 2

Views: 2491

Answers (1)

Cordon Davies
Cordon Davies

Reputation: 211

Figured it out!! I looked at what I got when I manually went into the mongo shell to see what I got back using the findOne('_id', 'myusername') and discovered that somewhere along the line my password is getting deleted (or more likely overwritten by something else) from the document and thus cannot retrieve it later leading to the error "Incorrect arguments". Now I just need to figure out where that is happening and fix it!

Upvotes: 4

Related Questions