Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Node.js and Mongoose: Connection Hanging On find() [Code Snippet]

DZone's Guide to

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.

· Web Dev Zone
Free Resource

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

Following 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:

Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

Topics:
mongoose ,node.js ,rest ,api ,express ,mongodb

Published at DZone with permission of Kevin Hooke, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}