Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6649175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:44:33+00:00 2026-05-26T00:44:33+00:00

Having trouble saving an embedded array to a Mongoose model. Please see Edit at

  • 0

Having trouble saving an embedded array to a Mongoose model.

Please see Edit at bottom.

I have a form to create BlogPost in Express using Mongoose to store data in mongo. I can create and view new blogposts however I just added an embedded document schema Feed into the BlogPost model and I can’t get Feed arrays to save from the form into the model

code:

BlogPosts.js

var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/my_database');

var Schema = mongoose.Schema
  , ObjectId = Schema.ObjectId;

var Feeds = new Schema({
    name      : { type: String }
  , key       : { type: String }
});

var BlogPost = new Schema({
    author    : ObjectId
  , title     : { type: String, required: true, index: { unique: true } }
  , date      : { type: Date, required: true, default: Date.now }
  , feeds     : [Feeds]
});

mongoose.model('BlogPost', BlogPost);

web.js

...
app.get('/blogpost/new', function(req, res) {
    res.render('blogposts/blogpost_new.jade', { locals: {
        title: 'New BlogPost'
    }
    });
});

app.post('/blogpost/new', function(req, res){
    var b = new BlogPost(req.body.b)
    b.save(function() {
      b.feeds.push();
      res.redirect('/blogposts');
    });
});
...
var BlogPost = mongoose.model('BlogPost', BlogPost);

Jade form

form( method="post")
  div
    div
      span Title :
      input(type="text", name="b[title]", id="editBlogPostTitle")
    div 
      span Feeds :
      ul 
        li 
          span name
          textarea( name="f[name]", rows=20, id="editBlogPostBodyName")
        li
          span key
          textarea( name="f[key]", rows=20, id="editBlogPostBodyKey")
    div#editBlogPostSubmit
      input(type="submit", value="Send")

If I fill out this form, the model posts and saves but the feeds data isn’t there ("feeds" : [ ]).

How should I properly submit the feeds data to save to the array?

Edit

So I have managed to set up a form to save a Feed object with name and key within a BlogPost doing the following. However, this still needs to be improved to allow for multiple Feeds to be saved at the time of creating a single BlogPost. With my current solution I can only save one Feed properly. Thoughts?

blogposts.js (just change Feeds to Feed

var Feed = new Schema({
...

web.js (just moved the push)

app.post('/blogpost/new', function(req, res){
    var b = new BlogPost(req.body.b)
    b.feeds.push(req.body.feed);
    b.save(function() {
      res.redirect('/blogposts');
});

});

form (just change feed names)

    li
        span name
        textarea( name="feed[name]", rows=20, id="editBlogPostBodyKey")
    li
        span key
        textarea( name="feed[key]", rows=20, id="editBlogPostBodyKey")

This saves properly, I just can’t create multiple feeds within a blogpost at the time of saving. Any help greatly appreciated. thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:44:34+00:00Added an answer on May 26, 2026 at 12:44 am

    For what it’s worth, I did get this to work. See my edit above which worked once I added an [] to the feed name: "feed[0][name]" and "feed[0][key]", and then "feed[1][name]" and "feed[1][key]". Thanks Chance for some good ideas. For me it didn’t work to put that logic in the ‘get’ route, it needed to be in the ‘post’. Thanks a lot tho.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble saving my entities to the database using EntityFramework. I have
I am having a little bit trouble with the following. I have multiple form
I'm having trouble saving a new row in the DataGridView back to the database.
I having trouble in dividing the HTML frames. I have been using the following
I am having trouble with IE7. I have a header, which is an IMG.
I'm having trouble with global variables in php. I have a $screen var set
I'm having trouble saving an entity into an SQL Server 2005 database. I'm using
I am having trouble saving a dotplot to pdf when this command is done
I'm having trouble saving a many-to-many relationship with nhibernate. I searched and looked at
I am having some trouble saving the state of my current view. Currenly I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.