Suppose I have the following schema:
"_id" : 1,
"n" : [{
"a" : ObjectId("4ef0ca414653b7c866040000"),
"d" : new Date("Thu, 22 Dec 2011 04:53:56 GMT +04:00")
}, {
"a" : ObjectId("4ef0ca414653b9c866040000"),
"d" : new Date("Thu, 22 Dec 2011 04:54:11 GMT +04:00")
}, {
"a" : ObjectId("4ef0ca424653b9c866040000"),
"d" : new Date("Thu, 22 Dec 2011 04:54:30 GMT +04:00"),
}]
and I need to remove all n, where d is less than specific date.
So I thought I will be able to do this in the following way:
db.coll.update({
'_id': 1
},{
$pullAll : {
n.d : {
$lte : new Date(2000, 10, 11)
}
}
})
but the problem is, that it is not working this way.
Any suggestions?
That is not how $pullAll works. You cannot specify a matching condition, you can only specify an array of objects to be deleted (that need to match exactly).
Fortunately, you can use $pull instead (which does accept a matching condition):
Note that $pull also pulls all elements that match, not just one.
This is admittedly a little confusing.