FG
🗄️ DatabasesMongoDB

Support for Asynchronous Virtual

Freshabout 12 years ago
Mar 14, 20260 views
Confidence Score76%
76%

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

Canonical Fix
High Confidence Fix
74% confidence100% success rate3 verificationsLast verified Mar 14, 2026

Solution: Support for Asynchronous Virtual

Low Risk

@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.

74

Trust Score

3 verifications

100% success
  1. 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...

    text
    myObjectSchema.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. 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

Worked: 3
Partial: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

mongoosemongodbodm