【发布时间】:2015-01-12 13:59:53
【问题描述】:
我想知道是否可以在 Keystone.js 中使用保存在 json 文件中的信息将字段添加到集合中。 我会告诉你我的问题:
而不是
Collection.add({
aaa: {
type: String,
required: false
},
bbb: {
type: String,
required: false
},
ccc: {
type: String,
required: false
}
}); // this works!
我想这样添加字段:
json_model = require(process.env.PWD + process.env.JSON_MODELS +'/collection.json'), //path of json file
var tmp_json = modelFromJsonFunc.json4model(json_model);
Projects.add(tmp_json);
输出是
{
aaa: {
type: String,
required: false
},
bbb: {
type: String,
required: false
},
ccc: {
type: String,
required: false
}
}
...
使用 mongo shell 我看到这个集合没有字段! 为什么不起作用? 感谢您的帮助。
【问题讨论】:
-
keystone 在后台使用 mongoose,因此您可以搜索 mongoose stackoverflow.com/questions/8504446/… 的答案
-
@HarryMoreno 上面的评论是绝对正确的。他推荐的问题的答案适用于 Mongoose 模式,但没有考虑 Keystone 类型。
标签: json model keystonejs