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.
An error used when attempting to parse a value (like a connection string)
To connect a Node. js application to MongoDB, we have to use a library called Mongoose. mongoose. connect("mongodb://localhost:27017/collectionName", { useNewUrlParser: true, useUnifiedTopology: true });
MongoDB has an uncomplicated web-based central port at 28017 by default. At the default port of 27017, there is no HTTP access. The error port is used for native driver access, not HTTP traffic. To obtain MongoDB, you'll need to use a driver like the MongoDB essential driver for NodeJS.
1.3 close() method in the Mongo database In the Mongo universe, the close() method instructs the server to close a cursor and free the associated server resources. The server will automatically close the cursors that have no remaining results and the cursors that have been idle for a time.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With