lundi 6 novembre 2017

Mongodb + nodejs doesn't connect with localhost

I'm keep trying myself to connect local mongo server via nodejs. Here's simple tutorial given by official mongodb, but doesn't hook once part.

var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function () {
    // we're connected!
    console.log("connected");
});

here's package.json of my project:

{
    "name": "MVC-Express-Application",
    "description": "An Express.js application using the MVC design pattern...",
    "version": "0.0.1",
    "dependencies": {
        "body-parser": "1.4.3",
        "errorhandler": "1.1.1",
        "express": "4.4.4",
        "express-handlebars": "1.1.0",
        "mongoose": "^3.8.8",
        "morgan": "1.1.1"
    }
}

when i type mongo they say

MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
Server has startup warnings:
2017-11-07T07:58:20.003+0900 I CONTROL  [initandlisten]
2017-11-07T07:58:20.003+0900 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-11-07T07:58:20.003+0900 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-11-07T07:58:20.003+0900 I CONTROL  [initandlisten]

so it should say connected on console but doesn't. Anybody knows how to deal with it? I tried reinstalling mongo via brew.

Thanks.

macOS Sierra 10.12.6 node v7.6.0




Aucun commentaire:

Enregistrer un commentaire