Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Users = mongoose.UserSchema;
- ApiUserSchema;
- Users.find(function(err,users){
- //for each user that mongoose finds,
- //I want to convert from UserSchema to "ApiUserSchema"
- //Something like the following:
- newUsers = users.ToApiUserSchema();
- console.log(newUsers);
- })
- function toApiUserSchema(user){
- username = user.username;
- email = user.email;
- someAggregate = user.Username + user.Email;
- .......and so on.....;
- }
- 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))
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement