je to velmi jednoduché. získat index/pozici posledního prvku.
var data = {
"_id" : "5d648b0d5aeada5177bb54e4",
"time" : [
{
"start" : "2019/8/25 9:59:30",
"end" : "2019/8/25 10:59:30"
},
{
"start" : "2019/8/26 9:59:30",
"end" : "2019/8/26 10:59:30"
},
{
"start" : "2019/8/27 9:59:30",
"end" : "2019/8/26 9:59:30"
}
]
}
var len = data.time.length - 1;
var objUpdate = {};
var updateQuery = "time." + len + ".end";
objUpdate[updateQuery] = "2019/8/26 11:59:30";
db.getCollection('test').update({"_id" : ObjectId("5d648b0d5aeada5177bb54e4")}, {$set:objUpdate});