Skip to content

Instantly share code, notes, and snippets.

@jrthib
Created May 9, 2013 05:47
Show Gist options
  • Save jrthib/5545787 to your computer and use it in GitHub Desktop.
Save jrthib/5545787 to your computer and use it in GitHub Desktop.
Sample NodeJS MongoDB model
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, crypto = require('crypto')
/**
* User Schema
*/
var UserSchema = new Schema({
createdAt: { type: Date, default: Date.now, required: true },
firstName: { type: String, required: true },
lastName: { type: String, required: true },
email: { type: String, required: true },
phone: { type: String, required: true },
username: String,
hashed_password: String,
authData: {
authType: { type: String, required: true },
id: { type: Number, required: true, unique: true, index: true },
expiration_date: { type: Date, required: true },
access_token: { type: String, required: true, unique: true }
},
access_token: { type: String, unique: true }
});
var validatePresenceOf = function (value) {
return value && value.length
}
mongoose.model('User', UserSchema);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment