Need to modify json and return inside aync find operation Need to modify json and return inside aync find operation mongoose mongoose

Need to modify json and return inside aync find operation


One simple approach you could take is to use the $in operator with the array of ids in your query, then apply the lean() method to return plain JS objects as Mongoose documents do not allow adding of properties.

Check out this example:

User.find({ "_id": { "$in": ['5781635026d6fad4486d81e9', '578296e31029e27b4ea53e9d'] } })    .lean()    .exec()    .then(function(docs) {          var users = docs.map(function(user) {            user["test"] = "lol";            return user;        });        res.send(users);    })