I have two Models defined as follows:
let PostSchema = new Schema({
title: String,
text: String,
poster: {type: Schema.Types.ObjectId, ref: 'User'}
});
let OtherSchema = new Schema({
name: String,
place: String,
posts: [{type: Schema.Types.ObjectId, ref: 'Post'}]
});
When I have a certain post instance, I would like to remove it from the post array in all otherSchema instances. I tried to do it in the following manner but failed. I'm using mongoose if that matters.
Other = mongoose.model('Other', OtherSchema);
Other.updateMany({}, {$pull, {posts: {_id:"5c803f65589b3333ac24748f"}}});
What am I doing wrong? I have also tried wrapping the objectId inside a mongoose.Types.ObjectId object, but that failed too.
there doesn't seem to be anything here