微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – 无法使用’in’运算符来搜索’_id’

我正在尝试使用mongoose和express来获取现有的用户文档,但我只能得到这个:

/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)

有没有任何已知的解决方案?谢谢.

解决方法:

这个错误并不是Mongoose特有的;它会显示obj不是一个对象,而是一个字符串,例如:

var obj = 'Account';
'id' in obj;
// TypeError: Cannot use 'in' operator to search for 'id' in Account

假设它不是一个Mongoose问题,你会在这里寻找某个地方:

at Object.findOrCreateOneForTwitter 
    (/webroot/api.domain.com/production/models/account.coffee:60:17)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐