I like to find a plan purchasedPlans.plan for a certain user(email) and then update its status to "Active"
const userSchema = new Schema({
email: String ,
purchasedPlans:[{plan:String , status:String,}]
});
What is the code in Mongoose.
You can use positional operator $, like this:
User.updateOne({
"email": "user_email",
"purchasedPlans.plan": "plan_to_change_status"
},{
"$set": {
"purchasedPlans.$.status": "Active"
}
})