Support for Asynchronous Virtual
Problem
I'd like to express some virtual properties that perform asynchronous work, such as inspecting other Mongoose models. It would be nice if the virtual getters and setters accepted an optional done function that would be invoked after the async work completed.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Support for Asynchronous Virtual
@vkarpov15 have you tried your suggestion? Consider the case of an api that wants to add virtual properties... [code block] For the asynch virtual to be useful, the find would need to resolve only after the virtuals have. Please prove me wrong about this, because I really need a promise-returning virtual to work.
Trust Score
3 verifications
- 1
@vkarpov15 have you tried your suggestion? Consider the case of an api that wan
@vkarpov15 have you tried your suggestion? Consider the case of an api that wants to add virtual properties...
textmyObjectSchema.virtual('property').get(function() { return // an unresolved promise }); // in a controller MyObject.findOne({ _id:id }, function(err, instance) { res.json(instance); console.log(instance.property); // not useful --> {"emitter": .... }); - 2
For the asynch virtual to be useful, the find would need to resolve only after t
For the asynch virtual to be useful, the find would need to resolve only after the virtuals have. Please prove me wrong about this, because I really need a promise-returning virtual to work.
Validation
Resolved in Automattic/mongoose GitHub issue #1894. Community reactions: 4 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep