我想知道是否可以使用保存在 json 文件中的信息在 Keystone.js 中将字段添加到集合中。我会告诉你我的问题:
代替
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 我看到这个集合没有字段!为什么不起作用?感谢您的任何帮助。