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
node.js mongoose


source to share


No one has answered this question yet

Check out similar questions:

4
Update document with error: Crash for line at line undefined
2
findByIdAndUpdate throws an error on try and updates the property to zero
1
500: Pass to ObjectId failed
1
Cast error: Cast to String could not get value when trying to find it
0
Getting error while searching for object by id using mongoose
0
Mongoose for Nodejs Express: drop in objectid failed for value
0
Posting array of objects to MongoDB in formData (ValidationError)
0
findOneAndUpdate doesn't work using MEAN stack
0
Mongoose refuses to give valid ObjectId string



All Articles
Loading...
X
Show
Funny
Dev
Pics