TypeError: Object prototype may only be an Object or null: undefined

TypeError: Object prototype may only be an Object or null: undefined

mongodb@4.12.1

This is simply running the nodejs quickstart. but replacing the uri with localhost uri, i.e “http://localhost:27017”. This has nothing to do with ipv6.

Hi, @tyson_N_A . that example you tried to use dates back to 2 years and has this in its README file:

“this branch uses MongoDB 4.4, MongoDB Node.js Driver 3.6.4, and Node.js 14.15.4”

Using old examples with new drivers is always expected to give rise to problems. And since newer drivers use TypeScript, you should take extra care. check other version references and API documents here: MongoDB Node.js Driver

hey again @tyson_N_A , I went ahead and run the code from that quickstart. Seems the code in it is still applicable and runs fine. So I urge you to check how you used that example. I am surprised you didn’t get “Invalid scheme” error for your URI as the driver gives error and asks for it to be of the form mongodb:// or mongodb+srv:// (for the localhost it is uri = "mongodb://localhost:27017").

when it is an IPv4 versus IPv6 issue, the error we get is very distinctive compared to other errors: ECONNREFUSED ::1:27017. and there are two things to cause this:

  • there is no server running, or the port is wrong.
  • the hosts file has both of these lines in use actively and the driver uses whichever comes first (or last, I always confuse that order)
    • 127.0.0.1       localhost
      ::1             localhost
      
1 Like