I'm new to Strongloop and newish to MongoDB. So many learning curves going on right now.
My basic issue is I switched the user model (models.json) datasource from the memory connector to the loopback-connector-mongodb connector and I no longer get a userId when I call /login. I get back an accesstoken, but the userID is null. If I switch back to the memory connector, I'll get a userId of 1 or whatever.
It seems like I remember reading somewhere if I do not supply an ID Strongloop would add one for me. Is this only for the in-memory datastore? Do I need to do something special since it's mongo?
Do I need to switch the accessToken model to mongo as well (I just thought of this)?
thanks.
You hit an edge case here: user and accessToken are backed by two different types of DBs. MongoDB uses ObjectID as the default key while memory DB uses number.
accessToken extends from base AccessToken. It inherits the belongsTo relation to base User model. The userId type is set to number. To fix the problem, you can either make sure accessToken model is connected to mongodb or add the following relation in models.json.
"accessToken": {
"dataSource": "db",
"public": true,
"options": {
"base": "AccessToken",
"relations": {
"user": {
"model": "user",
"type": "belongsTo",
"foreignKey": "userId"
}
}
}
},