我「當我運行的mongod m如果此消息。「等待在端口27017連接」連接到貓鼬
在我做的教程中,我想我應該得到的東西,如」連接從127.0接受.0.16:6。」
我檢查了這個職位已經 - mongod HostnameCanonicalizationWorker error on OS X
,我有我的主機文件設置爲這樣:
127.0.0.1 localhost
127.0.0.1 Bens-MacBook-Pro.local
255.255.255.255 broadcasthost
::1 localhost
這些都是我的爲節點腳本:
// Main starting point of the application
const express = require('express');
const http = require('http');
const bodyParser = require('body-parser');
const app = express();
const morgan = require('morgan');
const router = require('./router');
const mongoose = require('mongoose');
// DB Setup
mongoose.connect('mongodb://localhost:auth/auth');
// App Setup
app.use(morgan('combined'));
app.use(bodyParser.json({type: '*/*' }));
router(app);
// Server Setup
const port = process.env.PORT || 3090;
const server = http.createServer(app);
server.listen(port);
console.log('Server listening on:', port);
這是日誌的mongod:
2016-11-20T16:33:13.095-0700 I CONTROL [initandlisten] MongoDB starting : pid=15054 port=27017 dbpath=/data/db 64-bit host=Bens-MacBook-Pro.local
......
2016-11-20T16:33:13.380-0700 I NETWORK [initandlisten] waiting for connections on port 27017
缺少什麼?
謝謝!
修訂
http://code.runnable.com/UWxv-JS8trEHAACH/connect-to-mongodb-using-mongoosejs-for-node-js
我添加了一個監聽器來檢查連接:
/*
* More details here http://mongoosejs.com/docs/index.html
*/
//require mongoose node module
var mongoose = require('mongoose');
//connect to local mongodb database
var db = mongoose.connect('mongodb://127.0.0.1:27017/test');
//attach lister to connected event
mongoose.connection.once('connected', function() {
console.log("Connected to database")
});
而且它記錄 「連接到數據庫」,所以似乎是甚至認爲蒙古窗口說它不是。讓我通讀本教程的其餘部分,看看它是否真正連接。
@ AndrewM16。感謝您回覆。我將它改爲「mongoose.connect('mongodb:// localhost/auth');」它仍然沒有連接。 –