Modify objects returned by Mongoose
You could create static method for this on user Schema. Its important that you define static method between schema and model creation. Also note that find
returns array not one object.
var userSchema = new mongoose.Schema({ username: String, email: String, password: Number})userSchema.statics.toApiUserSchema = function(data) { return data.map(function(user) { return { email: user.email, username: user.username, emailAndUsername: user.email + user.username } })}var User = mongoose.model('User', userSchema)User.find({}, function(err, users) { console.log(User.toApiUserSchema(users))})