Closed awesomelike closed 3 years ago
You cannot remove and add a field in the same aggregate stage to my knowledge. I would use these two stages:
[
...
{ $addFields: { id: "$_id" } },
{ $project: { _id: 0 } },
...
]
Have not tested with this library, though.
Yes, this works
In my schema, I have a mongoose virtual field
id
which is equal to_id
. Generally, it works fine.However, when I use this library, this virtual field is not working (it is showing
_id
, but theid
virtual field disappeared). I have tried$project
stage in the aggregation pipeline:But it is removing all other fields from the response, (only
id
is there). It is very annoying to explicitly list all the necessary fields withfield1
: 1,field2
: 1What is the proper way to rename
_id
field to id while using this library? In other words, how to keep virtuals fields?