我有一个猫鼬对象架构,类似于以下内容:
var postSchema = new Schema({
imagePost: {
images: [{
url: String,
text: String
}]
});
我正在尝试使用以下内容创建新帖子:
var new_post = new Post();
new_post.images = [];
for (var i in req.body.post_content.images) {
var image = req.body.post_content.images[i];
var imageObj = { url: image['url'], text: image['text'] };
new_post.images.push(imageObj);
}
new_post.save();
但是,一旦我保存帖子,它就会使用图像属性的空数组创建。我究竟做错了什么?
你错过了imagePost
新对象中架构的对象。试试这个:
var new_post = new Post();
new_post.imagePost = { images: [] };
for (var i in req.body.post_content.images) {
var image = req.body.post_content.images[i];
var imageObj = { url: image['url'], text: image['text'] };
new_post.imagePost.images.push(imageObj);
}
new_post.save();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)