mongoosejs / mongoose-lean-virtuals

Attach virtuals to the results of mongoose lean() queries
Apache License 2.0
45 stars 24 forks source link

Allow virtual nested objects to work #43

Closed rdougan closed 4 years ago

rdougan commented 4 years ago

I noticed that nested virtuals are supported, but do not work if they are an object:

const schema = new mongoose.Schema({
  nested: {
    test: {
      a: String
    }
  }
}, { id: false });

schema.virtual('nested.test2').get(function() {
  return this.nested.test;
});

Does not work:

.lean({virtuals: ['nested.test2']});

I've fixed it, added a test, and verified all existing tests pass.