我有这个模型
var PostSchema = new Schema({
username: {type: String},
message: {type: String}
});
我正在尝试保存一个自定义记录
var p = new Post({username: "wow", message:"Hello, world!"});
p.save(function(err, p) {
if (err) return console.error(err);
console.log(p);
});
但是收到错误
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' } } }