Sunday, 16 April 2017

Why my mongoose sample program cannot connect to mongoDB and I have no error report?

I am new in MongDB and I am trying to run sample code from the Mongoose

http://mongoosejs.com/docs/index.html

I put the code in one of my router where I can connect to the MongoDB server using the MongoClient successfully.

However, when I was trying to replace the code with the sample of Mongoose, it could not work and have no error report there.

Here is the code I wrote to connect the MongoDB

var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/project');

exports.userSignin = function (req, res) {


var user = req.body;
if (user) {
    var db = mongoose.connection;
    db.on('error', console.error.bind(console, 'connection error:'));
    db.once('open', function() {
       console.log('successful');
    });
} else {
    res.send(common.get_return_data(false, '', -1, 'no data received'));
}

};

I got no error in the command line

  server: { port: 3000 } }
  project:server Listening on port 3000 +0ms
POST /user/signin - - ms - -
POST /user/signin - - ms - -
POST /user/signin - - ms - -

It is strange because I set the listener to listen to the error. And I start my mongoDB server as well.

wireless-nat-inside:project Jiahui$ mongod --dbpath ./data
2017-04-16T11:36:16.147-0500 I CONTROL  [initandlisten] MongoDB starting : pid=8341 port=27017 dbpath=./data 64-bit

host=wireless-nat-inside.uiowa.edu 2017-04-16T11:36:16.148-0500 I CONTROL [initandlisten] db version v3.4.3 2017-04-16T11:36:16.148-0500 I CONTROL [initandlisten] git version: f07437fb5a6cca07c10bafa78365456eb1d6d5e1 2017-04-16T11:36:16.148-0500 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2k 26 Jan 2017 2017-04-16T11:36:16.148-0500 I CONTROL [initandlisten] allocator: system 2017-04-16T11:36:16.148-0500 I CONTROL [initandlisten] modules: none 2017-04-16T11:36:16.148-0500 I CONTROL [initandlisten] build environment: 2017-04-16T11:36:16.148-0500 I CONTROL [initandlisten] distarch: x86_64 2017-04-16T11:36:16.148-0500 I CONTROL [initandlisten] target_arch: x86_64 2017-04-16T11:36:16.148-0500 I CONTROL [initandlisten] options: { storage: { dbPath: "./data" } } 2017-04-16T11:36:16.151-0500 I - [initandlisten] Detected data files in ./data created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'. 2017-04-16T11:36:16.151-0500 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0), 2017-04-16T11:36:18.149-0500 I CONTROL [initandlisten] 2017-04-16T11:36:18.149-0500 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2017-04-16T11:36:18.150-0500 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2017-04-16T11:36:18.150-0500 I CONTROL [initandlisten] 2017-04-16T11:36:18.150-0500 I CONTROL [initandlisten] 2017-04-16T11:36:18.150-0500 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000 2017-04-16T11:36:18.162-0500 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory './data/diagnostic.data' 2017-04-16T11:36:18.163-0500 I NETWORK [thread1] waiting for connections on port 27017

In addition, the program did go into the if statement, which means the user is not empty there. I did the debug using the webstrom.



via Jiahui Zhou

No comments:

Post a Comment