Skip to content

Instantly share code, notes, and snippets.

@NMZivkovic
Created October 8, 2017 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NMZivkovic/ea4a6998ca923e0723f6b32ed1a1178f to your computer and use it in GitHub Desktop.
Save NMZivkovic/ea4a6998ca923e0723f6b32ed1a1178f to your computer and use it in GitHub Desktop.
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
// Define a schema.
var userSchema = new Schema({
name: String,
blog: String,
age: Number,
location: String
});
// Define a method for concatanation of name and blog fields.
userSchema.methods.concatanceNameAndBlog = function() {
// Extend name with value of the blog field.
this.name = this.name + this.blog;
return this.name;
};
// Create a model.
var User = mongoose.model('User', userSchema);
module.exports = User;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment