title: Mongoose validation CastError: Cast to string failed for value
body: <p>I am trying to run my .js script in node but while adding some new data in database the server is not loading and giving this error(CastError: Cast to string failed for value). I am not getting the error can someone please help me out?Attaching the SS of cmd and the code as well![enter image description here][1]</p>
  <pre><code>Code is as follows:
  
  
  var express=require(&quot;express&quot;);
  var app= express();
  var bodyParser=require(&quot;body-parser&quot;);
  app.use(bodyParser.urlencoded({extended:true}));
  app.set(&quot;view engine&quot;,&quot;ejs&quot;);
  var mongoose=require(&quot;mongoose&quot;);
  
  mongoose.set(&quot;useNewUrlParser&quot;,  true);
  mongoose.set(&quot;useUnifiedTopology&quot;,true);
  mongoose.connect(&quot;mongodb://localhost/yelp_camp&quot;);
  
  var campgroundsschema= new mongoose.Schema({
      name:String,
      image:String
  });
  
  var Campground= mongoose.model(&quot;Campground&quot;,campgroundsschema);
  
  
  //Campground.create(
    //  {
      //  name:&quot;Granite Hill&quot;,
        //image:&quot;https://images.unsplash.com/photo-1487750404521-0bc4682c48c5?ixlib=rb-1.2.1&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;auto=format&amp;fit=crop&amp;w=500&amp;q=60&quot;
      //},function(err,campgrounds){
        //if(err){
         //   console.log(err);
        //}
        //else{
         //   console.log(&quot;We have created a new campground&quot;);
          //  console.log(campgrounds);
        //}
      //}
      //)
  
  
  app.get(&quot;/&quot;,function(req,res){
      res.render(&quot;landing&quot;);
  });
  
  
  app.get(&quot;/campgrounds&quot;,function(req,res){
       
       Campground.find({},function(err,allCampgrounds){
          if(err){
              console.log(err);
          }
          else{
              res.render(&quot;campgrounds&quot;,{campgrounds:allCampgrounds});
          }
       });
  });
  
  app.post(&quot;/campgrounds&quot;,function(req,res){
    var name=req.body.name;
    var image=req.body.image;
    var newCampground={name: name,image: image};
    Campground.create(newCampground,function(err,newlyCreated){
      if(err){
          console.log(err);
      }
      else{
          console.log(&quot;we have created a new campground here!!&quot;);
            res.redirect(&quot;/campgrounds&quot;);
          }
    });
  });
  
  app.get(&quot;/campgrounds/new&quot;,function(req,res){
       res.render(&quot;newcamp.ejs&quot;);
  
   });
  
  
  var port = process.env.PORT || 3000;
  
  app.listen(port, function () {
    console.log('Example app listening on port ' + port + '!');
  });
  
  
  Error ScreenShot:  [1]: https://i.stack.imgur.com/9vNPz.png
  </code></pre>
  <p>( please open this link to view the image)</p>