Node mongodb: Error: connection closed due to parseError

隐身守侯 提交于 2019-12-09 05:31:25

问题


Using the native 'mongodb' npm package, I'm receiving

Error: connection closed due to parseError

When making a very basic query:

 collections.myCollection.findOne({id: someID}, function (err, repo) {
    ...  
 })

The weird thing is, the exact same query has run before. Types are identical for each query, etc.


回答1:


Answering my own question to hopefully stop the next person from tearing their hair out:

As noted here, this error message is useless and doesn't relate to the actual problem. The production Mongo driver throws away all errors in a catch block.

To find what the error actually is:

  • open your node_modules/mongodb

  • find server.js

  • look for mongoReply.parseBody

  • log the err to see something actually useful.

In my case:

ReferenceError: collection is not defined

Edit: Node MongoDB native 1.4 is now stable, and includes a fix to this bug.




回答2:


For people who are using mongoose instead mongodb can check in the following location for the same.

/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection



来源:https://stackoverflow.com/questions/19546561/node-mongodb-error-connection-closed-due-to-parseerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!