I experiment a bug with MongoDB using code from the shopping application example. Specifically, I copied the code for Login/User authentication in my own code (with no modifications).
Remember there are two models: User and UserCredentials linked by a HasOne relation. when you create a new user you store the password in UserCredentials with:
await this.userRepository.userCredentials(savedUser.id).create({ password });
and the result in MongoDB is:
_id: ObjectId("5e2f24850570630bc9e3f558")
password: "$2a$10$/ZGqyHNotLYeKT7uSotXpuIHVMWmfEVROMKRqtIgEufqg0plibkC2"
userId:"5e2f24850570630bc9e3f557"
The problem here is when you try to get the credentials with:
await this.userCredentials(userId).get();
you get an ENTITY_NOT_FOUND error. The reason is the last line of code try to get the credentials with userId being an ObjectId, not a string. So the create function should make it an ObjectId. I checked, manually changing userId type to ObjectId make it works.
I am very confused about this behavior. What should I do?
https://github.com/strongloop/loopback-next/issues/3720
https://github.com/strongloop/loopback-next/issues/3456
My bad, this issue is resolved, I was using loopback-connector-mongodb 4.x instead of 5.x...
Paul.
Most helpful comment
My bad, this issue is resolved, I was using loopback-connector-mongodb 4.x instead of 5.x...
Paul.