Node mongodb: Error: connection closed due to parseError
Asked Answered
D

2

12

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.

Dichromatic answered 23/10, 2013 at 15:54 Comment(0)
D
29

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.

Dichromatic answered 23/10, 2013 at 15:56 Comment(1)
Thanks for the hour. I'll try to spend it wisely. In my case (twice now), I've traced it back to an unhandled exception in my callback code. Be sure to handle exceptions in your callbacks or they could get obscured by the calling context.Lathrop
C
1

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

Chercherbourg answered 16/5, 2017 at 9:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.