更新嵌入式mongoDB数据库中的数据

时间:2016-05-16 08:36:44

标签: c# mongodb

大家好我创建了以下数据库MongoDB我想更新数组任务中的数据但是我不能这样做我想知道是否有人可以帮助我这里是我的代码和我的数据库:
enter image description here

        MongoDBHandler h = new MongoDBHandler();
        MongoDatabase database = h._database;
        MongoCollection process = h.process;
        BsonDocument processusImport = new BsonDocument();
        BsonArray tasks = new BsonArray();

        tasks.Add(new BsonDocument
       {
       { "name","validation"},
       { "startDate",""},
       { "endDate",""},
       { "message",""},
       { "status","   "}
       });

        tasks.Add(new BsonDocument
       {
       { "name","GetStockValues"},
       { "startDate",""},
       { "endDate",""},
       { "message",""},
       { "status","   "}
       });

        tasks.Add(new BsonDocument
       {
       { "name","WriteInExcel"},
       { "startDate",""},
       { "endDate",""},
       { "message",""},
       { "status","   "}
       });

        tasks.Add(new BsonDocument
       {
       { "name","CopyToArchive"},
       { "startDate",""},
       { "endDate",""},
       { "message",""},
       { "status","   "}
       });

        tasks.Add(new BsonDocument
       {
       { "name","PrepareUpload"},
       { "startDate",""},
       { "endDate",""},
       { "message",""},
       { "status","   "}
       });

        processusImport.Add("task", tasks);

       processusImport["marque"] = "aaaa";
       processusImport["inputFile"] = "azerty";
       processusImport["processQueue"] =0;
        process.Insert(processusImport);

1 个答案:

答案 0 :(得分:0)

使用以下查询进行更新,希望这有助于您的事业

db.Process.update({"task.name":"validation"},{$set:{"task.$.startDate":"someDate","task.$.endDate":"someDate","task.$.message":"someMessage","task.$.status":"someStatus"}})