You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
Bug. May be an enhancement, but a necessary one.
What is the current behavior?
Validator functions don't have access to the session being used in a transaction.
In my case I have a reference validator that checks that the references inserted actually exist in the DB. The problems is that if I insert a document inside a transaction and then use it in a reference field, the validator tries to find it, but fails because it needs to use the session in the query.
Calling this.$session() inside the validator function returns null, so I can't use that.
If the current behavior is a bug, please provide the steps to reproduce.
Standalone script:
What is the expected behavior?
Either the validator function should have access to the same session that was passed down to the .create method (probably as a third param), or this.$session() should return that same session.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node.js: 10.15.1
Mongoose: 5.4.9
MongoDB: 4.0.4
I'll get started on a PR this weekend if I can.
Edit: Updated standalone script.
The text was updated successfully, but these errors were encountered:
mateo-gallardo
changed the title
Session isn't available in validators
Transaction's session isn't available in validators
Mar 27, 2019
vkarpov15
added
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
and removed
has repro script
There is a repro script, the Mongoose devs need to confirm that it reproduces the issue
labels
Apr 15, 2019
Can someone please explain how the this.$session() is supposed to work? When I'm trying to access it within the validator, I'm getting my own class member as the reference of "this", and not the schema (which is what I'm guessing the intention is).
I can't find any documentation for it as well.
Do you want to request a feature or report a bug?
Bug. May be an enhancement, but a necessary one.
What is the current behavior?
Validator functions don't have access to the session being used in a transaction.
In my case I have a reference validator that checks that the references inserted actually exist in the DB. The problems is that if I insert a document inside a transaction and then use it in a reference field, the validator tries to find it, but fails because it needs to use the session in the query.
Calling
this.$session()
inside the validator function returnsnull
, so I can't use that.If the current behavior is a bug, please provide the steps to reproduce.
Standalone script:
What is the expected behavior?
Either the validator function should have access to the same session that was passed down to the
.create
method (probably as a third param), orthis.$session()
should return that same session.What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node.js: 10.15.1
Mongoose: 5.4.9
MongoDB: 4.0.4
I'll get started on a PR this weekend if I can.
Edit: Updated standalone script.
The text was updated successfully, but these errors were encountered: