Last active
November 22, 2017 08:55
-
-
Save mjarpitanand/f852416bbad6ffc5b6f916589ed7b07f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install mongoose --save | |
very impo - mongoose.connect('mongodb://localhost/advisorDemoTestDB', { useMongoClient: true }) | |
var mongoose = require('mongoose'); | |
var Schema = mongoose.Schema; | |
var adminSchema = new Schema({ | |
email : { type : String, required : true}, | |
password : {type : String , required : true} | |
}) | |
var admin = mongoose.model('admin' , adminSchema); | |
Allowed datatype | |
The allowed SchemaTypes are: | |
String | |
Number | |
Date | |
Buffer | |
Boolean | |
Mixed | |
ObjectId | |
Array | |
userSchema.pre('save', function(next) { | |
// get the current date | |
var currentDate = new Date(); | |
// change the updated_at field to current date | |
this.updated_at = currentDate; | |
// if created_at doesn't exist, add to that field | |
if (!this.created_at) | |
this.created_at = currentDate; | |
next(); | |
}); | |
app.use(morgan('dev')); | |
morgan is just used to, show in console what all get and post that means REST api going through. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment