Yeah, this is not possible in find()
query. So, you should use the aggregate query if you want MongoDB to do this for you:
this.userModel.aggregate([
{
$match: usersFilterQuery
},
{
$project: {
age: '$ageUser'
}
}
]);
There is more thing that you can do. You can set virtual property in your Schema model, and Mongoose will create these for you on the fly (they will not be stored in the database). So, you will tell Mongoose to add age
property to each document that would be equal to the existing ageUser
property.
You can check more in the official docs.