0
我一直在關注有關MEAN堆棧的很多教程,並且我遇到了一個難以回答的問題(注意:我發現一個可能duplicate搜索時,但不相信它回答我的問題)Node.js和mongoose module.exports模型vs Schema
就拿這個代碼,可以發現here
// app/models/nerd.js
// grab the mongoose module
var mongoose = require('mongoose');
// define our nerd model
// module.exports allows us to pass this to other files when it is called
module.exports = mongoose.model('Nerd', {
name : {type : String, default: ''}
});
完成教程後,我重寫了代碼試圖複製像這樣的課程(「菜單項」爲剋制):
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}
}]
});
我將使用界面來創建新的菜單項。我應該保持原樣,還是使用Schema?