I have a model that looks like this:
mongoose.Schema({
username: String,
posts: [{ type: Schema.Types.ObjectId, ref: 'Post' }]
});
I have an endpoint that I want to pass an ObjectID:
app.delete('/post', function(req, res) {
User.findOne({ _id: req.user._id}, function(err, result) {
result.pull({ _id: req.body.post_id });
});
});
Feels like it should work, but I'm getting this error:
CastError: Cast to ObjectId failed for value "[object Object]"
What am I doing wrong?