如何更新mongodb中的子子文档

时间:2017-05-14 23:48:45

标签: node.js mongodb

我想更新这个文件,当使用议程。$ .margetime.0只是第一个文件在margetime更新,当使用议程。$ .margetime.1第二个文件更新,我想通过id子子文件更新,请帮帮我?

`{ 
"value" : true, 
"content" : "11 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b53") }`


my request :

      Employer.update({"agenda._id" :req.params.subid,
        "agenda.margetime._id" :req.params.subsubid},
        {"$set": {"agenda.$.margetime.$": req.body}}, function (err,data) {
        res.jsonp(data);
        })});

我的文件:

`{ 
"_id" : ObjectId("59006181fa528b0bb8874878"), 
"name" : "aicha", 
"phoneNumber" : "06125482595", 
"idresponsable" : ObjectId("58e258a44587261a34cf8bb4"), 
"updatedAt" : ISODate("2017-04-26T08:59:45.662+0000"), 
"createdAt" : ISODate("2017-04-26T08:59:45.662+0000"), 
"email" : "aicha@gmail.com", 
"__v" : NumberInt(4), 
"idsalon" : ObjectId("5900bd96a3d5fa05d4dc5b26"), 
"endTime" : "1970-01-01T18:00:00.000Z", 
"rate" : NumberInt(30), 
"startTime" : "1970-01-01T08:00:00.000Z", 
"agenda" : [
{
"day" : "lundi", 
"_id" : ObjectId("591849164fb23515c0e80b44"), 
"margetime" : [
{
"_id" : ObjectId("5918aac2516e0c14086a7257"), 
"cause" : "malade", 
"content" : "8 : 31", 
"value" : true
}, 
{
"_id" : ObjectId("5918ab8cbfdfeb04fc76979c"), 
"cause" : "malade", 
"content" : "8 : 32", 
"value" : true
}, 
{
"value" : true, 
"content" : "9 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b57")
}, 
{
"value" : true, 
"content" : "9 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b56")
}, 
{
"value" : true, 
"content" : "10 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b55")
}, 
{
"value" : true, 
"content" : "10 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b54")
}, 
{
"value" : true, 
"content" : "11 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b53")
}, 
{
"value" : true, 
"content" : "11 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b52")
}, 
{
"value" : true, 
"content" : "12 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b51")
}, 
{
"value" : true, 
"content" : "12 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b50")
}, 
{
"value" : true, 
"content" : "13 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b4f")
}, 
{
"value" : true, 
"content" : "13 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b4e")
}, 
{
"value" : true, 
"content" : "14 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b4d")
}, 
{
"value" : true, 
"content" : "14 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b4c")
}, 
{
"value" : true, 
"content" : "15 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b4b")
}, 
{
"value" : true, 
"content" : "15 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b4a")
}, 
{
"value" : true, 
"content" : "16 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b49")
}, 
{
"value" : true, 
"content" : "16 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b48")
}, 
{
"value" : true, 
"content" : "17 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b47")
}, 
{
"value" : true, 
"content" : "17 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b46")
}, 
{
"value" : true, 
"content" : "18 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b45")
}
]
}, 
{
"day" : "mardi", 
"_id" : ObjectId("591849164fb23515c0e80b2e"), 
"margetime" : [
{
"value" : true, 
"content" : "8 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b43")
}, 
{
"_id" : ObjectId("591864bf0a615011382cf2e1"), 
"cause" : "conge", 
"content" : "8 : 30", 
"value" : false
}, 
{
"value" : true, 
"content" : "9 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b41")
}, 
{
"value" : true, 
"content" : "9 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b40")
}, 
{
"value" : true, 
"content" : "10 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b3f")
}, 
{
"value" : true, 
"content" : "10 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b3e")
}, 
{
"value" : true, 
"content" : "11 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b3d")
}, 
{
"value" : true, 
"content" : "11 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b3c")
}, 
{
"value" : true, 
"content" : "12 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b3b")
}, 
{
"value" : true, 
"content" : "12 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b3a")
}, 
{
"value" : true, 
"content" : "13 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b39")
}, 
{
"value" : true, 
"content" : "13 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b38")
}, 
{
"value" : true, 
"content" : "14 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b37")
}, 
{
"value" : true, 
"content" : "14 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b36")
}, 
{
"value" : true, 
"content" : "15 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b35")
}, 
{
"value" : true, 
"content" : "15 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b34")
}, 
{
"value" : true, 
"content" : "16 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b33")
}, 
{
"value" : true, 
"content" : "16 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b32")
}, 
{
"value" : true, 
"content" : "17 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b31")
}, 
{
"value" : true, 
"content" : "17 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b30")
}, 
{
"value" : true, 
"content" : "18 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b2f")
}
]
}, 
{
"day" : "mercredi", 
"_id" : ObjectId("591849164fb23515c0e80b18"), 
"margetime" : [
{
"value" : true, 
"content" : "8 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b2d")
}, 
{
"value" : true, 
"content" : "8 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b2c")
}, 
{
"value" : true, 
"content" : "9 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b2b")
}, 
{
"value" : true, 
"content" : "9 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b2a")
}, 
{
"value" : true, 
"content" : "10 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b29")
}, 
{
"value" : true, 
"content" : "10 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b28")
}, 
{
"value" : true, 
"content" : "11 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b27")
}, 
{
"value" : true, 
"content" : "11 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b26")
}, 
{
"value" : true, 
"content" : "12 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b25")
}, 
{
"value" : true, 
"content" : "12 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b24")
}, 
{
"value" : true, 
"content" : "13 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b23")
}, 
{
"value" : true, 
"content" : "13 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b22")
}, 
{
"value" : true, 
"content" : "14 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b21")
}, 
{
"value" : true, 
"content" : "14 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b20")
}, 
{
"value" : true, 
"content" : "15 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b1f")
}, 
{
"value" : true, 
"content" : "15 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b1e")
}, 
{
"value" : true, 
"content" : "16 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b1d")
}, 
{
"value" : true, 
"content" : "16 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b1c")
}, 
{
"value" : true, 
"content" : "17 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b1b")
}, 
{
"value" : true, 
"content" : "17 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b1a")
}, 
{
"value" : true, 
"content" : "18 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b19")
}
]
}, 
{
"day" : "jeudi", 
"_id" : ObjectId("591849164fb23515c0e80b02"), 
"margetime" : [
{
"value" : true, 
"content" : "8 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b17")
}, 
{
"value" : true, 
"content" : "8 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b16")
}, 
{
"value" : true, 
"content" : "9 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b15")
}, 
{
"value" : true, 
"content" : "9 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b14")
}, 
{
"value" : true, 
"content" : "10 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b13")
}, 
{
"value" : true, 
"content" : "10 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b12")
}, 
{
"value" : true, 
"content" : "11 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b11")
}, 
{
"value" : true, 
"content" : "11 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b10")
}, 
{
"value" : true, 
"content" : "12 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b0f")
}, 
{
"value" : true, 
"content" : "12 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b0e")
}, 
{
"value" : true, 
"content" : "13 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b0d")
}, 
{
"value" : true, 
"content" : "13 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b0c")
}, 
{
"value" : true, 
"content" : "14 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b0b")
}, 
{
"value" : true, 
"content" : "14 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b0a")
}, 
{
"value" : true, 
"content" : "15 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b09")
}, 
{
"value" : true, 
"content" : "15 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b08")
}, 
{
"value" : true, 
"content" : "16 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b07")
}, 
{
"value" : true, 
"content" : "16 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b06")
}, 
{
"value" : true, 
"content" : "17 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b05")
}, 
{
"value" : true, 
"content" : "17 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b04")
}, 
{
"value" : true, 
"content" : "18 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b03")
}
]
}, 
{
"day" : "vendredi", 
"_id" : ObjectId("591849164fb23515c0e80aec"), 
"margetime" : [
{
"value" : true, 
"content" : "8 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b01")
}, 
{
"value" : true, 
"content" : "8 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80b00")
}, 
{
"value" : true, 
"content" : "9 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80aff")
}, 
{
"value" : true, 
"content" : "9 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80afe")
}, 
{
"value" : true, 
"content" : "10 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80afd")
}, 
{
"value" : true, 
"content" : "10 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80afc")
}, 
{
"value" : true, 
"content" : "11 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80afb")
}, 
{
"value" : true, 
"content" : "11 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80afa")
}, 
{
"value" : true, 
"content" : "12 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80af9")
}, 
{
"value" : true, 
"content" : "12 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80af8")
}, 
{
"value" : true, 
"content" : "13 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80af7")
}, 
{
"value" : true, 
"content" : "13 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80af6")
}, 
{
"value" : true, 
"content" : "14 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80af5")
}, 
{
"value" : true, 
"content" : "14 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80af4")
}, 
{
"value" : true, 
"content" : "15 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80af3")
}, 
{
"value" : true, 
"content" : "15 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80af2")
}, 
{
"value" : true, 
"content" : "16 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80af1")
}, 
{
"value" : true, 
"content" : "16 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80af0")
}, 
{
"value" : true, 
"content" : "17 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80aef")
}, 
{
"value" : true, 
"content" : "17 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80aee")
}, 
{
"value" : true, 
"content" : "18 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80aed")
}
]
}, 
{
"day" : "samedi", 
"_id" : ObjectId("591849164fb23515c0e80ad6"), 
"margetime" : [
{
"value" : true, 
"content" : "8 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80aeb")
}, 
{
"value" : true, 
"content" : "8 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80aea")
}, 
{
"value" : true, 
"content" : "9 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ae9")
}, 
{
"value" : true, 
"content" : "9 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ae8")
}, 
{
"value" : true, 
"content" : "10 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ae7")
}, 
{
"value" : true, 
"content" : "10 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ae6")
}, 
{
"value" : true, 
"content" : "11 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ae5")
}, 
{
"value" : true, 
"content" : "11 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ae4")
}, 
{
"value" : true, 
"content" : "12 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ae3")
}, 
{
"value" : true, 
"content" : "12 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ae2")
}, 
{
"value" : true, 
"content" : "13 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ae1")
}, 
{
"value" : true, 
"content" : "13 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ae0")
}, 
{
"value" : true, 
"content" : "14 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80adf")
}, 
{
"value" : true, 
"content" : "14 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ade")
}, 
{
"value" : true, 
"content" : "15 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80add")
}, 
{
"value" : true, 
"content" : "15 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80adc")
}, 
{
"value" : true, 
"content" : "16 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80adb")
}, 
{
"value" : true, 
"content" : "16 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ada")
}, 
{
"value" : true, 
"content" : "17 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ad9")
}, 
{
"value" : true, 
"content" : "17 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ad8")
}, 
{
"value" : true, 
"content" : "18 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ad7")
}
]
}, 
{
"day" : "dimanche", 
"_id" : ObjectId("591849164fb23515c0e80ac0"), 
"margetime" : [
{
"value" : true, 
"content" : "8 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ad5")
}, 
{
"value" : true, 
"content" : "8 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ad4")
}, 
{
"value" : true, 
"content" : "9 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ad3")
}, 
{
"value" : true, 
"content" : "9 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ad2")
}, 
{
"value" : true, 
"content" : "10 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ad1")
}, 
{
"value" : true, 
"content" : "10 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ad0")
}, 
{
"value" : true, 
"content" : "11 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80acf")
}, 
{
"value" : true, 
"content" : "11 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ace")
}, 
{
"value" : true, 
"content" : "12 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80acd")
}, 
{
"value" : true, 
"content" : "12 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80acc")
}, 
{
"value" : true, 
"content" : "13 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80acb")
}, 
{
"value" : true, 
"content" : "13 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80aca")
}, 
{
"value" : true, 
"content" : "14 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ac9")
}, 
{
"value" : true, 
"content" : "14 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ac8")
}, 
{
"value" : true, 
"content" : "15 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ac7")
}, 
{
"value" : true, 
"content" : "15 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ac6")
}, 
{
"value" : true, 
"content" : "16 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ac5")
}, 
{
"value" : true, 
"content" : "16 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ac4")
}, 
{
"value" : true, 
"content" : "17 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ac3")
}, 
{
"value" : true, 
"content" : "17 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ac2")
}, 
{
"value" : true, 
"content" : "18 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("591849164fb23515c0e80ac1")
}
]
}
]
}
{ 
"_id" : ObjectId("590061d3fa528b0bb8874879"), 
"name" : "meryem", 
"phoneNumber" : "06125289", 
"idresponsable" : ObjectId("58e258a44587261a34cf8bb4"), 
"updatedAt" : ISODate("2017-04-26T09:01:07.553+0000"), 
"createdAt" : ISODate("2017-04-26T09:01:07.553+0000"), 
"email" : "meryem@gmail.com", 
"__v" : NumberInt(0), 
"idsalon" : ObjectId("5900bd96a3d5fa05d4dc5b26"), 
"endTime" : "1970-01-01T18:00:00.000Z", 
"rate" : NumberInt(20), 
"startTime" : "1970-01-01T08:00:00.000Z"
}
{ 
"_id" : ObjectId("5900758ffa22a716400b44fb"), 
"name" : "mbarka", 
"phoneNumber" : "06258964", 
"idresponsable" : ObjectId("58fdedaf9b3c8b13f8493730"), 
"updatedAt" : ISODate("2017-04-26T10:25:19.693+0000"), 
"createdAt" : ISODate("2017-04-26T10:25:19.693+0000"), 
"email" : "mbarka@gmail.com", 
"__v" : NumberInt(0)
}
{ 
"_id" : ObjectId("59027b5b80d9e610ec2ee93d"), 
"name" : "khadija", 
"phoneNumber" : "06251894", 
"idresponsable" : ObjectId("58fdedaf9b3c8b13f8493730"), 
"updatedAt" : ISODate("2017-04-27T23:14:35.077+0000"), 
"createdAt" : ISODate("2017-04-27T23:14:35.077+0000"), 
"email" : "khadija@gmail.com", 
"__v" : NumberInt(0)
}
{ 
"_id" : ObjectId("5909fdb6752af00c64cd3a5d"), 
"name" : "ballouk mohaamed", 
"phoneNumber" : "0655888888", 
"idresponsable" : ObjectId("58e258a44587261a34cf8bb4"), 
"updatedAt" : ISODate("2017-05-03T15:56:38.493+0000"), 
"createdAt" : ISODate("2017-05-03T15:56:38.493+0000"), 
"email" : "ballouk@gmail.com", 
"__v" : NumberInt(0), 
"idsalon" : ObjectId("5900d316a3d5fa05d4dc5b27"), 
"endTime" : "1970-01-01T17:00:00.000Z", 
"rate" : NumberInt(30), 
"startTime" : "1970-01-01T07:00:00.000Z"
}
{ 
"_id" : ObjectId("590b3595a4a1dc061c14ebb1"), 
"name" : "fatima", 
"phoneNumber" : "06587952", 
"idresponsable" : ObjectId("58e258a44587261a34cf8bb4"), 
"updatedAt" : ISODate("2017-05-04T14:07:17.396+0000"), 
"createdAt" : ISODate("2017-05-04T14:07:17.396+0000"), 
"email" : "fatima@gmail.com", 
"__v" : NumberInt(2), 
"idsalon" : ObjectId("5900d316a3d5fa05d4dc5b27"), 
"endTime" : "1970-01-01T08:00:00.000Z", 
"rate" : NumberInt(30), 
"startTime" : "1970-01-01T06:00:00.000Z", 
"agenda" : [
{
"day" : "lundi", 
"_id" : ObjectId("59170239f610da0980829c3c"), 
"margetime" : [
{
"value" : true, 
"content" : "6 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c41")
}, 
{
"value" : true, 
"content" : "6 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c40")
}, 
{
"value" : true, 
"content" : "7 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c3f")
}, 
{
"value" : true, 
"content" : "7 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c3e")
}, 
{
"value" : true, 
"content" : "8 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c3d")
}
]
}, 
{
"day" : "mardi", 
"_id" : ObjectId("59170239f610da0980829c36"), 
"margetime" : [
{
"value" : true, 
"content" : "6 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c3b")
}, 
{
"value" : true, 
"content" : "6 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c3a")
}, 
{
"value" : true, 
"content" : "7 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c39")
}, 
{
"value" : true, 
"content" : "7 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c38")
}, 
{
"value" : true, 
"content" : "8 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c37")
}
]
}, 
{
"day" : "mercredi", 
"_id" : ObjectId("59170239f610da0980829c30"), 
"margetime" : [
{
"value" : true, 
"content" : "6 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c35")
}, 
{
"value" : true, 
"content" : "6 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c34")
}, 
{
"value" : true, 
"content" : "7 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c33")
}, 
{
"value" : true, 
"content" : "7 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c32")
}, 
{
"value" : true, 
"content" : "8 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c31")
}
]
}, 
{
"day" : "jeudi", 
"_id" : ObjectId("59170239f610da0980829c2a"), 
"margetime" : [
{
"value" : true, 
"content" : "6 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c2f")
}, 
{
"value" : true, 
"content" : "6 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c2e")
}, 
{
"value" : true, 
"content" : "7 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c2d")
}, 
{
"value" : true, 
"content" : "7 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c2c")
}, 
{
"value" : true, 
"content" : "8 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c2b")
}
]
}, 
{
"day" : "vendredi", 
"_id" : ObjectId("59170239f610da0980829c24"), 
"margetime" : [
{
"value" : true, 
"content" : "6 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c29")
}, 
{
"value" : true, 
"content" : "6 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c28")
}, 
{
"value" : true, 
"content" : "7 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c27")
}, 
{
"value" : true, 
"content" : "7 : 30", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c26")
}, 
{
"value" : true, 
"content" : "8 : 0", 
"cause" : "nothing", 
"_id" : ObjectId("59170239f610da0980829c25")
}
]
}
]
}
]
}
]
}`

2 个答案:

答案 0 :(得分:1)

不幸的是,mongo仅支持单级阵列更新。如果已知数组内的数组索引,$将对您有所帮助。你可以使用这样的东西 -

> Employer.update({"agenda._id" :req.params.subid,
        "agenda.margetime._id" :req.params.subsubid}, {$set:{"agenda.0.margetime.1":req.body}});

在提出问题之前你应该读过这些 - Update embedded object inside array inside array in MongoDB

Updating nested array inside array mongodb

答案 1 :(得分:0)

非常感谢mAky_0788先生的帮助,这是我的问题的解决方案:

    Employer.findById(req.params.employerId, function (e, data) {
        if (e) console.log(e);
        var t = data.agenda.id(req.params.subid).margetime.id(req.params.subsubid);
        t.content = req.body.content;
        t.value = req.body.value;
        t.cause = req.body.cause
        data.save();
 res.jsonp(t)
    });