Hello friends ,
I need a function to remove particular objects from a nested array ,please check the code as follow ,I have already tried a lot times ,but fail …Could you please help me ?Thank you so much in advance!
UserSchema :
userName: {
type: String,
},
specialList: [
{
type: mongoose.Types.ObjectId,
ref: "Friend",
},
],
FriendSchema:
userName:{
type:string
}
Now ,I need a function to delete some of the friends in a user’s specialList by their user’s id, For instance ,
//this is not working like I wish ...I have no idea what is going on ...
const needToRmoveList = ["123","456"];
await UserInfo.findOneAndUpdate(
{ _id: "345" },
{ $pull: { specialList: { id: { $in: [needToRmoveList] } } } },
{ new: true }
);