1

I am a beginner. I installed Bitnami MEAN stack and I have a question.

"[]" shows on the web page when I enter http://127.0.0.1:3000/tableList. I want to know why the web page does not show the data in collections.

On Command Prompt:

C:\Bitnami\meanstack-3.2.3-1\test>SET DEBUG=test:* & npm start

test@0.0.0 start C:\Bitnami\meanstack-3.2.3-1\test node ./bin/www test:server Listening on port 3000 +0ms connection successful [] GET /tableList 304 30.004 ms - - GET /favicon.ico 200 7.164 ms - 1183

On mongodb.log file:

2016-04-05T00:08:04.350+0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:52192 #6 (4 connections now open)
2016-04-05T00:08:04.513+0700 I ACCESS [conn6] Successfully authenticated as principal chai on khamoo

On app.js file:

var mongoose = require('mongoose');

mongoose.connect('mongodb://chai:chai@localhost/khamoo', function(err) {
  if(err) {
    console.log('connection error', err);
  } else {
    console.log('connection successful');
  }
});

mongoose.model('tableList',{tid: String});

app.get('/tableList', function(req, res) {
  mongoose.model('tableList').find(function(err,tableList){
    console.log(tableList);
    res.json(tableList);
  });
});
  • have you checked err? – AJS Apr 06 '16 at 12:00
  • what error that I must check? [] show on web browser and no error when I press F12. no error on mongodb.log file. – BasicMEANuser Apr 06 '16 at 17:19
  • ** mongoose.model('tableList').find(function(err,tableList){** err variable log it see if there is anything there – AJS Apr 07 '16 at 05:42
  • 1
    app.get('/tableList', function(req, res) { mongoose.model('tableList').find({}, function(err,tableList){ if(err){ console.log('error', err); } else{ console.log('no error'); console.log(tableList); res.json(tableList); } }); }); – BasicMEANuser Apr 08 '16 at 17:48
  • I insert if-else statement follow you suggest but result no error. – BasicMEANuser Apr 08 '16 at 17:56
  • I found solution from http://stackoverflow.com/questions/5794834/how-to-access-a-preexisting-collection-with-mongoose. – BasicMEANuser Apr 09 '16 at 18:14

0 Answers0