Skip to content

Instantly share code, notes, and snippets.

@WillieYang
Created July 22, 2017 16:19
Show Gist options
  • Select an option

  • Save WillieYang/500ec10b51fc13e59bfcc5e95e0c22f5 to your computer and use it in GitHub Desktop.

Select an option

Save WillieYang/500ec10b51fc13e59bfcc5e95e0c22f5 to your computer and use it in GitHub Desktop.
what is the method: mongoose.model();
// Require the Mongoose
var mongoose = require('mongoose');
// Schema for user
var UserSchema = new mongoose.Schema({
username: {type: String, required: true},
email: {type: String, unique: true, required: true},
password: {type: String, required: true},
});
// Compiling the Schema into Model
// First parameter is the name of model,
// and the second parameter is the name of schema.
mongoose.model('User', UserSchema);
// as for the mongoose.model above, it can be used when interacting with mongoDB.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment