mongodb - Node.js and mongoose module.exports on a model vs Schema -


i have been following many tutorials concerning mean stack, , have come question i've found hard answer (note: found possible duplicate when searching, don't believe answers question)

take code example, can found here

// app/models/nerd.js // grab mongoose module var mongoose = require('mongoose'); // define our nerd model // module.exports allows pass other files when called module.exports = mongoose.model('nerd', {   name : {type : string, default: ''} }); 

after finishing tutorial, rewrote code attempt replicate lessons ("menu item" restraunt):

var mongoose = require('mongoose');  module.exports = mongoose.model('item', {   name: {type: string, required: true},   description: {type: string, require: true},   price: {type: string, required: true},   ingredients: [{     name: {type: string, default: ''},     amt: {type: string, enum: ['none', 'reg', 'xtra'], required: true}   }] }); 

i using interface create new menu items. should leave code is, or use schema?

well. reading through code post example difference, , came this.

var mongoose     = require('mongoose'); var schema       = mongoose.schema;  var bearschema   = new schema({     name: string });  module.exports = mongoose.model('bear', bearschema); 

i noticed schema defined inline (i think?) instead of being declared. assume because later, cleaner me add more schema declarations in model, along methods. if can provide me clarification, i'll give answer!


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -