我有一个模型,看起来像这样:
mongoose.Schema({
username: String,
posts: [{ type: Schema.Types.ObjectId, ref: 'Post' }]
});
我有一个终端点(endpoint),我想通过一个ObjectID传递参数:
app.delete('/post', function(req, res) {
User.findOne({ _id: req.user._id}, function(err, result) {
result.pull({ _id: req.body.post_id });
});
});
感觉应该可以工作,但是我收到了这个错误:
CastError: 将值“[object Object]”转换为ObjectId失败
我做错了什么?