To convert Mongoose docs to JSON with Node.js, we use the lean method.
For instance, we write
UserModel.find()
.lean()
.exec((err, users) => {
return res.end(JSON.stringify(users));
});
to call lean to convert the results returned from find to a plain object.
Then we get the results from the users parameter in the exec callback.
users is a plain JavaScript array.