1

I have a mongodb Collection called History:

{
"_id" : ObjectId("58e374f06e1cdc455ca49bb1"),
"creationtime" : ISODate("2017-04-04T10:26:57.185Z"),
"loginName" : "someone",
"retries" : [ 
    {
        "number" : 1,
        "retryTime" : ISODate("2017-04-04T10:26:57.185Z"),
        "_id" : ObjectId("58e374f16e1cdc455ca49bb2")
    }, 
    {
        "number" : 2,
        "retryTime" : ISODate("2017-04-04T10:32:19.476Z"),
        "_id" : ObjectId("58e3763393cb982f5f335905")
    }, 
    {
        "number" : 3,
        "retryTime" : ISODate("2017-04-04T10:32:29.284Z"),
        "_id" : ObjectId("58e3763d93cb982f5f335906")
    }
],
"__v" : 2
}

I want to remove all documents in the collection, which the last index of the "retries" array is greater then some value.

var now = new Date()
History.remove({ "retries.[retries.length -1]" : { $gte: now }},function(err,result) {

});

This is obviously not how it can be done, I was wandering how can it be implemented (I just made up the retries.[retries.length -1] part) any way I can query the last element in the array? and remove the document based on the above query?

toto
  • 1,197
  • 2
  • 15
  • 26

0 Answers0