mongoose lean query, virtuals not showing
i found a solution you can use mongoose-lean-virtuals plugin
https://www.npmjs.com/package/mongoose-lean-virtuals
lean
queries return raw MongoDB
driver response as a plain js
object. So, there are no getters
, setters
, virtuals
or other "Mongoose magic" in it. See Api docs for more info.
The point of lean
queries is to return your objects as fast as possible. If you need virtuals
- use ordinary Mongoose queries.
As for aggregation, it's 100% MongoDB
feature and Mongoose can't control it. So, when you calling aggregate
from Mongoose it works the same as aggregate
in MongoDB
console. aggregate
can't operate with virtuals, because there are no such fields in your database. Mongoose can't even cast your aggregation query according to your schema (like it's doing with findOneAndUpdate
arguments), because aggregation changes the shape of the document on each step. See Mongoose API Docs and MongoDB Docs for more info.