I want to update chargeList isDelete property to true when date is greater than a specific value. my schema as follows.
{
"chargeList": [
{
"date": ISODate("2013-06-26T18:57:30.012Z"),
"price": "123",
"isDelete": false
},
{
"date": ISODate("2013-06-27T18:57:30.012Z"),
"price": "75",
"isDelete": false
}
]
}
schema is as follows.
var ChargeListSchema= new Schema({
date: { type: Date , default: Date.now },
price: { type: String, required: false },
isDelete: { type: Boolean, default: false }
});
var ScheduleChargeSchema = new Schema({
chargeList:[ChargeListSchema]
});
I have tried as following code but it only update the matching first element in chargeList array.
Model.update(
{
"_id": 1,
"chargeList": {
"$elemMatch": {
"date": {
$gt: ISODate("2013-06-26T18:57:30.012Z")
}
}
}
},
{
"$set": { "chargeList.$.isDelete": true }
}
)