2014-02-17 41 views
2

突然在我的登錄函數中出現這個錯誤,我無法弄清楚是什麼導致它。我檢查了使用查詢或插入MongoDB的兩種情況,但無法看到任何與參數有關的問題。在第一個參數中使用json,在第二個參數中使用json,我認爲這應該起作用,並且在我使用它的其他情況下似乎可以工作。我想我可能有語法錯誤(也許)或可能導致它的東西。有任何想法嗎?
首先蒙戈用法:MongoError:不正確的參數

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

二蒙戈用法:

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

以下是錯誤:

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) 

提前感謝!

回答

4

想通了!我查看了手動進入mongo shell以查看我使用findOne('_ id','myusername')得到的結果,並發現在該行的某處我的密碼被刪除(或更可能被別的東西),因此不能在稍後檢索它,導致錯誤「不正確的參數」。現在我只需要弄清楚發生的情況並修復它!