当我尝试将Node连接到MongoDB时出现此错误
(但是mongo和node都相当新,所以我可能做错了...)
MongoNetworkError:连接ECONNREFUSED 127.0.0.1:27017 在Socket.err(/var/www/rzp/api/web/server_node/node_modules/mongodb-core/lib/connection/connect.js:287:16) 在Object.onceWrapper(events.js:273:13) 在Socket.emit(events.js:182:13) 在emitErrorNT上(内部/流/destroy.js:82:8) 在emitErrorAndCloseNT(internal / streams / destroy.js:50:3) 在process._tickCallback(internal / process / next_tick.js:63:19)
Symfony Side
config.yml
doctrine_mongodb:
connections:
default:
server: "%mongodb_server%"
options: {}
default_database: rzp_users
document_managers:
default:
auto_mapping: true
parameters.yml
mongodb_server: "mongodb://127.0.0.1:27017"
Node server.js
// Connection URL
const url = 'mongodb://127.0.0.1:27017';
MongoClient.connect(url, { useNewUrlParser: true }, function (err,client){
我认为我对Symfony的Mongo配置很好(不确定)
php bin/console doctrine:mongodb:generate:documents AppRefactoredBundle
Generating documents for "AppRefactoredBundle"
generating AppRefactoredBundle\Document\UserConnected
感谢您的帮助。