Node.js and Mongoose: Connection Hanging On find() [Code Snippet]
A quick code snippet showing you how to debug some MongoDB errors when building REST APIs on Node.js with Express.
Join the DZone community and get the full member experience.
Join For FreeFollowing this tutorial to build a simple REST API on Node.js with Express, attempting to retrieve all docs from my MongoDB gave these errors:
2016-05-19T20:10:47.311-0700 [initandlisten] connection accepted from 127.0.0.1:52053 #4 (2 connections now open)
2016-05-19T20:10:47.325-0700 [conn4] authenticate db: nodetest { authenticate: 1, user: "", nonce: "xxx", key: "xxx" }
2016-05-19T20:10:47.336-0700 [conn4] Failed to authenticate @nodetest with mechanism MONGODB-CR: ProtocolError field missing/wrong type in received authenticate command
Some quick Googling turned up the same error in this post that just suggested authentication was failing because no user was passed. So created a new used with:
db.createUser({user : 'nodetest', pwd: 'passwordhere', roles: ['readWrite', 'nodetest']})
… and problem solved.
Related Refcard:
Published at DZone with permission of Kevin Hooke, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments