我正在创建一篇博客文章,自动创建的ID永远不会在compose.io上进入我的MongoDB数据库
这是我的beforeCreate函数的json结果(仅用于测试)
{ free: true,
published: true,
title: 'Ojfwneof',
slug: 'ojfwneof',
post: 'njwornijerbn',
id: null }
以下是我在BlogController中创建函数的json结果:
{ free: true,
published: true,
title: 'hiurwgier',
slug: 'hiurwgier',
post: 'bfjirwbfejkrf',
id: '55887edba5bb4113e4173edd',
createdAt: Mon Jun 22 2015 16:32:11 GMT-0500 (CDT),
updatedAt: Mon Jun 22 2015 16:32:11 GMT-0500 (CDT) }
这是我的compose.io数据库中的json数据存储(注意id上的空值):
{
free: true,
published: true,
title: "fnjrwnk",
slug: "fnjrwnk",
post: "fnjkrwnjoewrn",
id: null,
createdAt: ISODate("2015-06-22T21:26:43.049Z"),
updatedAt: ISODate("2015-06-22T21:26:43.049Z"),
_id: ObjectId("55887d9308cdfe8de3ae78e6")
}
这是我的博客模型:
module.exports = {
attributes: {
free: {
type: 'boolean',
required: true,
defaultsTo: false
},
published: {
type: 'boolean',
required: true,
defaultsTo: false
},
title: {
type: 'string',
required: true
},
slug: {
type: 'string',
required: true
},
post: {
type: 'text',
required: true
}
},
beforeCreate: function(val, next) {
console.log(val);
next();
}
};
这是我的BlogController中的创建函数:
create: function(req, res) {
Blog.create(req.params.all(), function newPost (err, post) {
if(err) res.badRequest();
console.log(post);
res.json(post);
});
},