# Mongoose Subdocument Routes Issue

**URL:** <https://forum.freecodecamp.org/t/mongoose-subdocument-routes-issue/180070>\
**Category:** General\
**Created:** [March 16, 2018, 5:22pm UTC](https://forum.freecodecamp.org/t/mongoose-subdocument-routes-issue/180070 "2018-03-16T17:22:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MjRodge](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mjrodge/32/65066_2.png) [@MjRodge](https://forum.freecodecamp.org/u/MjRodge)\
**Post date:** [March 16, 2018, 5:22pm UTC](https://forum.freecodecamp.org/t/mongoose-subdocument-routes-issue/180070/1 "2018-03-16T17:22:25Z")

</div>

I’m currently trying to complete the voting app challenge, and I’m having problems adding an answer to a previously created question.

Currently, I can add polls, delete polls, and list all or by ID.

I’ve created my schemas using the following:

```auto
var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var AnswerSchema = new Schema({
  answer: String,
  votes: {
    type: Number,
    default: 0,
  }
});

var PollSchema = new Schema({
  question: String,
  answers: [AnswerSchema]
});

module.exports = mongoose.model('Poll', PollSchema);

```

And my route is currently:

```auto
router.route('/polls/:poll_id/add')

    // add answers to an existing poll (accessed at PUT http://localhost:8080/api/polls/:poll_id/add)
    .put(function(req, res) {
      Poll.findById(req.params.poll_id, function(err, poll) {
        if (err)
          res.send(err);

        poll.answers.push(req.body.answer);

        poll.save(function (err) {
          if (err)
            res.send(err);

          res.json({ message: 'Successfully added answer' });
        });
    });
});

```

Postman is throwing this error:

```auto
{
    "errors": {
        "answers.0._id": {
            "message": "Cast to ObjectID failed for value \"Test Answer\" at path \"_id\"",
            "name": "CastError",
            "stringValue": "\"Test Answer\"",
            "kind": "ObjectID",
            "value": "Test Answer",
            "path": "_id",
            "reason": {
                "message": "Cast to ObjectId failed for value \"Test Answer\" at path \"_id\"",
                "name": "CastError",
                "stringValue": "\"Test Answer\"",
                "kind": "ObjectId",
                "value": "Test Answer",
                "path": "_id"
            }
        }
    },
    "_message": "Poll validation failed",
    "message": "Poll validation failed: answers.0._id: Cast to ObjectID failed for value \"Test Answer\" at path \"_id\"",
    "name": "ValidationError"
}

```

Googling the error gives the suggestion to use [populate](http://mongoosejs.com/docs/populate.html), but I was using this [subdocument manual page](http://mongoosejs.com/docs/subdocs.html) as a guide. I’m unsure where my mistake is, or how to proceed. Does anybody have any advice?

Thanks!

---

<div class="post-metadata">

**Author:** ![bnoden](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bnoden/32/4753_2.png) [@bnoden](https://forum.freecodecamp.org/u/bnoden)\
**Post date:** [March 17, 2018, 12:22am UTC](https://forum.freecodecamp.org/t/mongoose-subdocument-routes-issue/180070/2 "2018-03-17T00:22:19Z")

</div>

> [@MjRodge](#):
>
> poll.answers.push(req.body.answer);

According to your Poll schema, shouldn’t `answer` be `answers`?

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:24pm UTC](https://forum.freecodecamp.org/t/mongoose-subdocument-routes-issue/180070/3 "2021-01-17T20:24:12Z")

</div>

Closed on January 17, 2021, 8:24pm UTC


