原生连接
1. error parsing command line options: unknown option "o"
版本问题,不支持-o
选项,使用--dir=<dbpath>
代替
mongorestore -h 127.0.0.1:27017 -d blog -u admin -p=qq1194132 --dir=/data/blog --authenticationDatabase admin
2. command listCollections requires authentication
和Failed: error connecting to db server: server return
mongodb
服务开启了验证登录,但是你没有验证,解决方法
- 添加:
-u <username> -p=<password>
- 添加:
--authenticationDatabase admin
mongorestore -h 127.0.0.1:27017 -d koa -u admin -p=123456 -o C:\Users\yq612\Desktop\koa --authenticationDatabase admin
mongoose
连接
1. mongoose
连接超时,MongoTimeoutError: Server selection timed out after 30000 ms
有两个原因:
- 没有添加
authSource=admin
mongoose.connect('mongodb://koa:123456@localhost:27017/koa?authSource=admin', { useNewUrlParser: true, useUnifiedTopology: true })
- 账户问题,账户没有通过
use admin
创建