0
我已經在顯示的keystone.js中創建了一個新模型'Product.js'。在keystone.js中更新模型數據庫模式
var keystone = require('keystone');
var Types = keystone.Field.Types;
var Product = new keystone.List('Product', {
map: {name: 'title'},
singular: 'Product',
plural: 'Products',
autokey: {path: 'slug', from: 'title', unique: true}
});
Product.add({
title: {type: String, required: true},
price: {type: Number},
qty: { type: Number },
description: {type: Types.Html, wysiwyg: true, height: 300},
image: {type: Types.CloudinaryImage},
publishedDate: {type: Date, default: Date.now}
});
Product.register();
我在管理界面看到這些屬性。現在我想更新它並動態地添加一個新的屬性(不更改此文件中的任何內容)。在路由文件product.js中,我可以創建新的實例(以下文章this)來填充像這樣的現有屬性。
keystone.createItems({
Product: [{
title: 'Product 3',
price: 34,
qty: 4,
description: "sldfkjslkfjlskdjfsdfj",
__ref: 'prod'
}]
}, function (err, stats) {
stats && console.log(stats.message);
});
是否有像這樣的功能可以更改產品架構?
我想在這個模型中在mongoose db中添加一個新屬性。我該怎麼做? keystone.js在Windows中存儲數據庫文件的位置?