MongoError:不正确的参数 [英] MongoError: Incorrect arguments

查看:40
本文介绍了MongoError:不正确的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

突然在我的登录功能中出现此错误,我无法弄清楚究竟是什么导致了它.我检查了使用查询或插入 MongoDB 的两种情况,但看不到参数有任何问题.只在第一个参数中使用 json,在第二个参数中使用回调函数,我认为这应该可以工作,并且在我使用它的其他情况下似乎也可以工作.我想我可能有语法错误(也许)或可能导致它的东西.有什么想法吗?
第一次使用 Mongo:

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
    });
}

第二次使用 Mongo:

Second Mongo usage:

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)

提前致谢!

推荐答案

想通了!!我查看了当我手动进入 mongo shell 以查看使用 findOne('_id', 'myusername') 返回的内容时得到的内容,并发现我的密码在某处被删除(或更可能被覆盖)其他东西)从文档中提取,因此以后无法检索它,从而导致错误参数不正确".现在我只需要弄清楚发生了什么并修复它!

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!

这篇关于MongoError:不正确的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆