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

Potential error in updateById and Mongoose adapter #360

Open
kree-alltold opened this issue Jul 7, 2023 · 1 comment
Open

Potential error in updateById and Mongoose adapter #360

kree-alltold opened this issue Jul 7, 2023 · 1 comment

Comments

@kree-alltold
Copy link

Hi, I have been using moleculer-db with the mongoose adapter successfully for several months now. I am not sure why this issue is just now showing itself, but I have noticed two potential problems, one in the adapter and one in the core db service code.

  1. In _update() you call beforeEntityChanged() here, but there is not corresponding call to entityChanged()` at the end of the function.
  2. In the mongoose adapter the method updateById() returns a Query object. For some reason I just started having to explicitly call exec() on the returned query to get a doc that I can send to transformDocuments(), otherwise I was getting the error enity.toJSON() is not a function.

Note that I use _update() (or the update action) when possible, however, there are cases where I need to do a more complicated update operation than what the db adapter supports and I call updateById directly and then call transformDocuments.

Any ideas if either of these are actual bugs in the code, or is this working as intended and I am must have done something else that broke things.

@icebob
Copy link
Member

icebob commented Jul 11, 2023

  1. Here is the calling of entityChanged:
    .then(json => this.entityChanged("updated", json, ctx).then(() => json));
  2. You don't need to call exec because the returned object is a Promise, so if you call it with await it will be executed without exec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants