我尝试将我的Loopback应用程序与MongoDb Atlas连接,但出现错误“ TypeError:无法读取null的属性'dbName'”。
以下是我尝试过的内容:
{
"db": {
"name": "db",
"connector": "mongodb"
},
"mongodb": {
"host": "",
"port": 0,
"url": "mongodb+srv://USER:PASSWORD@DATABASENAME-f4exx.mongodb.net/test?retryWrites=true&w=majority",
"database": "DATABASENAME",
"password": "PASSWORD",
"name": "mongodb",
"user": "dbAdmin",
"useNewUrlParser": true,
"connector": "mongodb"
}
}
每次尝试运行“ node”。 ,得到TypeError: Cannot read property 'dbName' of null
。
我已将我的IP添加到列入白名单的IP(MongoDB地图集)中
下面是我的model.config.json
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
],
"mixins": [
"loopback/common/mixins",
"loopback/server/mixins",
"../common/mixins",
"./mixins"
]
},
"User": {
"dataSource": "mongodb"
},
"AccessToken": {
"dataSource": "mongodb",
"public": false
},
"ACL": {
"dataSource": "mongodb",
"public": false
},
"RoleMapping": {
"dataSource": "mongodb",
"public": false,
"options": {
"strictObjectIDCoercion": true
}
},
"Role": {
"dataSource": "mongodb",
"public": false
}
}
PS:我正在使用环回3x
答案 0 :(得分:0)
发现将属性$dsn = getenv('MYSQL_DSN');
$user = getenv('MYSQL_USER');
$pw = getenv('MYSQL_PASSWORD');
//Database connection
$db = new PDO($dsn, $user, $pw);
//register value from <form> inputs
$username = $_POST['username'];
$password = $_POST['password'];
//insertion success
$statement = $db->prepare("insert into member values(null, '$username', SHA('$password'), now())");
$statement->execute();
设置为false可以解决我的问题。仍然不知道为什么这是根本原因。