title: Mongoose cannot update array: undefined error
body: <p>Please look at this code:</p>
  
  <pre><code>// Update route
  router.put("/:comment_id", function (req, res) {
      Campground.findOneAndUpdate(
          {"_id": req.params.id, "comments._id": req.params.comment_id },
          {"$set": {"comments.$.text": req.body.comment.text}},
          function (err, campground) {
              if (err) {
                  console.log("campground: " + campground); //logs campground: undefined
                  console.log("comment id: " + req.params.comment_id); // logs comment id: 5a5f2ab0a6dccd210c0136de
                  console.log("campground id: " + req.params.id); // logs campground id: 5a5e083af62da603900ab0d4
                  res.redirect("/campgrounds");
              } else {
                  res.redirect("/campgrounds/" + campground._id);
              }
          }
      );
  });
  </code></pre>
  
  <p>the ids refers to an url like this: </p>
  
  <pre><code>http://localhost:4000/campgrounds/5a5e083af62da603900ab0d4/comments/5a5e0845f62da603900ab0d5/edit
  </code></pre>
  
  <p>This is weird for me, why I cannot reach <code>campground</code>? In this way i cannot update the doc I need. Please help me to find a solution.</p>
  
  <p>EDIT: Error provided by <code>console.log(err);</code> :</p>
  
  <pre><code>{ CastError: Cast to ObjectId failed for value "secondo me no" at path "comments"
      at new CastError (folder\node_modules\mongoose\lib\error\cast.js:27:11)
      at ObjectId.cast (folder\node_modules\mongoose\lib\schema\objectid.js:158:13)
      at ObjectId.SchemaType.applySetters (folder\node_modules\mongoose\lib\schematype.js:695:12)
      at ObjectId.SchemaType._castForQuery (folder\node_modules\mongoose\lib\schematype.js:1066:15)
      at ObjectId.castForQuery (folder\node_modules\mongoose\lib\schema\objectid.js:198:15)
      at ObjectId.SchemaType.castForQueryWrapper (folder\node_modules\mongoose\lib\schematype.js:1035:15)
      at castUpdateVal (folder\node_modules\mongoose\lib\services\query\castUpdate.js:345:19)
      at walkUpdatePath (folder\node_modules\mongoose\lib\services\query\castUpdate.js:229:22)
      at castUpdate (folder\node_modules\mongoose\lib\services\query\castUpdate.js:72:18)
      at model.Query._castUpdate (folder\node_modules\mongoose\lib\query.js:2991:10)
      at castDoc (folder\node_modules\mongoose\lib\query.js:3017:18)
      at model.Query.Query._findAndModify (folder\node_modules\mongoose\lib\query.js:2292:19)
      at model.Query.Query._findOneAndUpdate (folder\node_modules\mongoose\lib\query.js:2139:8)
      at folder\node_modules\kareem\index.js:276:8
      at folder\node_modules\kareem\index.js:23:7
      at _combinedTickCallback (internal/process/next_tick.js:131:7)
    message: 'Cast to ObjectId failed for value "secondo me no" at path "comments"',
    name: 'CastError',
    stringValue: '"secondo me no"',
    kind: 'ObjectId',
    value: 'secondo me no',
    path: 'comments',
    reason: undefined }
  </code></pre>
  
  <p>@Younel this is the Edit view:</p>
  
  <pre><code>&lt;% include ../partials/header %&gt;
  &lt;div class="container"&gt;
      &lt;div class="row"&gt;
          &lt;h1 style="text-align: center;"&gt;Edit Comment&lt;/h1&gt;
          &lt;div style="width: 30%; margin:25px auto;"&gt;
              &lt;form action="/campgrounds/&lt;%= campground_id %&gt;/comments/&lt;%= comment._id %&gt;?_method=PUT" method="POST"&gt;
                  &lt;div class="form-group"&gt;
                      &lt;input class="form-control" type="text" name="comment[text]" value="&lt;%= comment.text %&gt;"&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      &lt;button class="btn btn-lg btn-primary btn-block"&gt;Submit!&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/form&gt;
              &lt;a href="/campgrounds"&gt;Go Back&lt;/a&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;% include ../partials/footer %&gt;
  </code></pre>
  
  <p>"secondo me no" is the <code>comment[text]</code> value</p>
  
  <p>This is a github repo: <a href="https://github.com/ufollettu/YelpCamp.git" rel="nofollow noreferrer">https://github.com/ufollettu/YelpCamp.git</a> (run v10/app.js)</p>