I have a mongoose object schema that looks something like this:
var postSchema = new Schema({ imagePost: { images: [{ url: String, text: String }] });
I am trying to create a new post using the following:
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();
However, as soon as I save the message, it is created with an empty array for the images property. What am I doing wrong?
James
source share