Manipulating data in a complex mongoDB data model -
{ name: “bimal”, role: “developer”, reports_to: “girish”, technology:[{ name: “php”, rating: 5 },{ name: “javascript”, rating: 4 }], project: [{ project_name: “tgt”, client_name: “said”, estimated_time: 20, tasks: [{ start_time: new date(2013, 2, 13, 7, 47), end_time: new date(2013, 2, 15, 7, 47), description: “design page” }, { start_time: new date(2013, 3, 13, 7, 47), end_time: new date(2013, 2, 13, 7, 47), description: “coding page” }] }]
}
i have complex database structure. need add new technology , rating after javascript.also need edit description of task has a description "design page".
to add new technology use either $push or $addtoset. update description in project section use positional operator $ $set . remember in subdocument order not maintain time . in case want order in technology key , please add 1 more key called order , use in each subdocument . while showing on client side can order . removed second query . 1 of way if wish limitation can pull data in client side , update document , save , there no direct command , have loop in client side
db.collection.update({"name" : "bimal"} , { "technology" : { $addtoset : { name: “new technology”,rating: 1}}})
if possible , if ok , can re structure document
{tasks : [{ "projectname: "" , startdate : "" , enddate : "" , description : "" } ]
i know duplicate data many times 1 of way can update fields in tasks sub document.
Comments
Post a Comment