Unable to convert to string

I have this model

var PostSchema = new Schema({
    username: {type: String},
    message:  {type: String}
});

      

and i am trying to save one user entry

var p = new Post({username: "wow", message:"Hello, world!"});
    p.save(function(err, p) {
        if (err) return console.error(err);
        console.log(p);
    });

      

but error

  message: 'Post validation failed',
  name: 'ValidationError',
  errors: 
   { username: 
      { message: 'Cast to String failed for value "wow" at path "username"',
        name: 'CastError',
        kind: 'String',
        value: 'wow',
        path: 'username' } } }

      

+3


source to share





All Articles