Wonderjar's Blog

Mongoose连接Mongo repilcaSet

2018-08-24

mongoose连接mongo repilcaSet
mogoose.connect(mongodb://XXX:XXX@HOST1:PORT1,HOST2:PORT2/XXX?replicaSet=XXXX, { useNewUrlParser: true })
报错Auth failed
解决办法,加上authSource,值可能是admin
mongodb://XXX:XXX@HOST1:PORT1,HOST2:PORT2/XXX?replicaSet=XXXX&authSource=XXX