Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDB ObjectId and HasOneRepository #4518

Closed
paeolo opened this issue Jan 27, 2020 · 1 comment
Closed

MongoDB ObjectId and HasOneRepository #4518

paeolo opened this issue Jan 27, 2020 · 1 comment
Labels

Comments

@paeolo
Copy link

paeolo commented Jan 27, 2020

Steps to reproduce

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?

Related Issues

#3720
#3456

@paeolo paeolo added the bug label Jan 27, 2020
@paeolo
Copy link
Author

paeolo commented Jan 28, 2020

My bad, this issue is resolved, I was using loopback-connector-mongodb 4.x instead of 5.x...
Paul.

@paeolo paeolo closed this as completed Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant