'How to get value of one virtual field from another?
I have two virtual fields. For example, A and B. I want to get the value of A from B. I tried to access the value using this but it returns undefined.
I have simplified my code here.
exampleSchema.virtual('A').get(function () {
return this.example ? true : false; // suppose I have a field called example in my document
});
exampleSchema.virtual('B').get(function () {
return this.A ? false : true; // this.A doesn't work. It returns undefined
});
Any help would be appreciated. Thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
