javascript 不能使用“in”运算符来搜索“_id”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14617367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot use 'in' operator to search for '_id' in
提问by optikfluffel
I'm trying to get an existing user document using mongoose with express but I only get this:
我正在尝试使用带有 express 的 mongoose 获取现有用户文档,但我只得到了这个:
/webroot/api.domain.com/production/node_modules/mongoose/lib/document.js:162
if (obj && '_id' in obj) continue;
^
TypeError: Cannot use 'in' operator to search for '_id' in Account
at model.Document._buildDoc (/webroot/api.domain.com/production/node_modules/mongoose/lib/document.js:162:27)
at model.Document (/webroot/api.domain.com/production/node_modules/mongoose/lib/document.js:67:20)
at model.Model (/webroot/api.domain.com/production/node_modules/mongoose/lib/model.js:33:12)
at new model (/webroot/api.domain.com/production/node_modules/mongoose/lib/model.js:1663:11)
at Object.model (/webroot/api.domain.com/production/node_modules/mongoose/lib/model.js:1662:14)
at Object.findOrCreateOneForTwitter (/webroot/api.domain.com/production/models/account.coffee:60:17)
at module.exports.callback.error (/webroot/api.domain.com/production/endpoints/twitter.coffee:67:34)
at Twitter.get (/webroot/api.domain.com/production/node_modules/ntwitter/lib/twitter.js:85:7)
at passBackControl (/webroot/api.domain.com/production/node_modules/oauth/lib/oauth.js:361:11)
at IncomingMessage.exports.OAuth._performSecureRequest.request.on.callbackCalled (/webroot/api.domain.com/production/node_modules/oauth/lib/oauth.js:380:9)
Is there any known fix for that? Thanks.
有没有已知的修复方法?谢谢。
采纳答案by Ja?ck
This error is not specific to Mongoose; it would show if obj
is not an object, but a string for instance:
这个错误不是猫鼬特有的;它会显示 ifobj
不是一个对象,而是一个字符串,例如:
var obj = 'Account';
'id' in obj;
// TypeError: Cannot use 'in' operator to search for 'id' in Account
Assuming that it's not a Mongoose issue, you'd be looking somewhere here:
假设这不是猫鼬问题,您会在这里寻找某个地方:
at Object.findOrCreateOneForTwitter
(/webroot/api.domain.com/production/models/account.coffee:60:17)
回答by Ali Gangji
Incidentally, you will get the same error from the dojo parser if you try to load an AMD module and you use require
instead of define
to define the module.
顺便说一句,如果您尝试加载 AMD 模块并使用require
而不是define
定义模块,则会从 dojo 解析器中得到相同的错误。