##mongodbに接続したい
環境
-centOS6
ドットインストール「Node.js入門」に従ってい学習中
やりたいこと
-仮想サーバとmongoDBを接続したい。
接続後”connected to db”と出力される
##エラー
//terminal [vagrant@localhost nodejs]$ node mongo.js /home/vagrant/nodejs/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:532 let sslOptions = { ^^^ SyntaxError: Unexpected strict mode reserved word at Module._compile (module.js:439:25) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:364:17) at require (module.js:380:17) at Object.<anonymous> (/home/vagrant/nodejs/node_modules/mongodb/node_modules/mongodb-core/index.js:19:15) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32)
//mongo.js var MongoClient = require('mongodb').MongoClient, settings = require('./settings'); MongoClient.connect("mongodb://"+settings.host+"/"+settings.db, function(err, db) { if (err) { return console.dir(err); } console.log("connected to db"); });
[vagrant@localhost nodejs]$ mongo 192.168.33.10 MongoDB shell version v3.6.2 connecting to: mongodb://192.168.33.10:27017/test 2018-01-27T16:59:24.142+0900 W NETWORK [thread1] Failed to connect to 192.168.33.10:27017, in(checking socket for error after poll), reason: Connection refused 2018-01-27T16:59:24.142+0900 E QUERY [thread1] Error: couldn't connect to server 192.168.33.10:27017, connection attempt failed : connect@src/mongo/shell/mongo.js:251:13 @(connect):1:6 exception: connect failed
やってみたこと
/etc/mongod.confの中を変更
参照ページ
Connection refused ということなので単純に疎通できていない可能性が高いですが、pingやtelnetなどで疎通確認してみてはいかがですか?
回答1件
あなたの回答
tips
プレビュー