askerovlab askerovlab - 1 year ago 53
Node.js Question

Application not opening get request to find() from database?

I was doing a simple app, that get, adds, shows new data. It all worked fine, but today it doesn't open the request, that is supposed to show items from database. Basically it just loads forever. First it wrote something about authentication, so I enabled it - But it didn't help. I am using mongoose, also it showed deprecation warnings for .connect, I changed it to mongoose.connection.openUri(), still didn't help.

When I try to access data from database this page just loads forever. Other pages that doesn't get data from database work fine.

Setup code:

var express = require('express'),
app = express(),
bodyParser = require('body-parser'),
mongoose = require('mongoose'); mongoose.connection.openUri('mongodb://adminUser:password@localhost:3000/db');
app.use(bodyParser.urlencoded({extended: true}));
app.set('view engine', 'ejs');

Problematic request:

app.get('/users', function(req, res) {
User.find({}, function(err, result) {
if(err) {
} else {
res.render('index', {users: result});

I use: Windows 8.1 x64 and it worked fine a day or two ago.

Output by mongod (if needed)output by mongod

I added debug option and changed a bit openURI (I clarified from what database I should get admin user, from the docs I got it, that you get admin from admin db):



Now mongod shows things like:enter image description here

Answer Source

I think has something to do with mongoClient. I changed the code from connection.openURI back to .connect. It gave me deprecation warning, and advised to use {useMongoClient: true}, which I did and the problem came back. So I set it to false, and it disappered, the warning again is here, but at least it works.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download