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 6630803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:27:29+00:00 2026-05-25T22:27:29+00:00

Possible Duplicate: Mongoose – Form to save model with embedded documents I have a

  • 0

Possible Duplicate:
Mongoose – Form to save model with embedded documents

I have a simple Mongoose schema with BlogPosts and Feeds embedded within those BlogPosts. So each BlogPost can have several Feed objects. Right now my HTML form allows me to correctly save one ‘Feed’ when I create a BlogPost, BUT I would like to be able to add many Feeds. How should I change my HTML/controller? Thanks much!

web.js

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

/blogpost/new

<form method="post">
    <input type="text" name="blogpost[title]"/>
    <textarea name="feed[name]"></textarea>
    <textarea name="feed[key]"></textarea>
    <textarea name="feed[name]"></textarea>
    <textarea name="feed[key]"></textarea>
</form>

schema

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

var BlogPost = new Schema({
  title     : { type: String, required: true, index: { unique: true } }
, feeds     : [Feed]
});

How do I make it so that this form stores two ‘Feeds’ in the blogpost object it creates? right now it would save One Feed in the data with two name values and two key values.

Thanks much!

  • 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-25T22:27:30+00:00Added an answer on May 25, 2026 at 10:27 pm

    When you do something like this:

    <textarea name="feed[name]"></textarea>
    <textarea name="feed[key]"></textarea>
    <textarea name="feed[name]"></textarea>
    <textarea name="feed[key]"></textarea>
    

    You are basically saying “I need a textbox for feed’s name, feed’s key, feed’s name, feed’s key which is obviously incorrect. If you did feed[0][name]…feed[1][name] that would say “i need a textbox for the first feed…i need a textbox for the second feed”

    Since you are breaking the parent and child up, rather than handling them as sub objects, you’ll need to push each into the blogPost.feeds and save it.

    Just be careful with that approach, especially when editing, because you are simply adding new objects ontop of what could already be an existing array of feeds.

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

Sidebar

Related Questions

Possible Duplicate: How to update GUI from another thread in C#? I have form
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: Why do I get a null pointer exception from TabWidget? I have
Possible Duplicate: How do pointer to pointers work in C? Hi All, I have
Possible Duplicate: Find out the instance id from within an ec2 machine I am
Possible Duplicate: Python urllib2 Progress Hook I have a script which uploads a file
Possible Duplicate: Split A4 PDF page into two A5 and back again I have
Possible Duplicate: Why does ReSharper want to use 'var' for everything? I have ReSharper
Possible Duplicate: css rule to disable text selection highlighting On my homepage i have
Possible Duplicate: Symfony2 AJAX Login I have implemented a custom authentication handler service to

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.