<i id='DEzwe'><tr id='DEzwe'><dt id='DEzwe'><q id='DEzwe'><span id='DEzwe'><b id='DEzwe'><form id='DEzwe'><ins id='DEzwe'></ins><ul id='DEzwe'></ul><sub id='DEzwe'></sub></form><legend id='DEzwe'></legend><bdo id='DEzwe'><pre id='DEzwe'><center id='DEzwe'></center></pre></bdo></b><th id='DEzwe'></th></span></q></dt></tr></i><div id='DEzwe'><tfoot id='DEzwe'></tfoot><dl id='DEzwe'><fieldset id='DEzwe'></fieldset></dl></div>
    • <bdo id='DEzwe'></bdo><ul id='DEzwe'></ul>
      <legend id='DEzwe'><style id='DEzwe'><dir id='DEzwe'><q id='DEzwe'></q></dir></style></legend>

      <small id='DEzwe'></small><noframes id='DEzwe'>

    1. <tfoot id='DEzwe'></tfoot>

        将元素插入到MongoDB中的嵌套数组中

        时间:2023-06-05

        <small id='3xI6i'></small><noframes id='3xI6i'>

            <tbody id='3xI6i'></tbody>
            <i id='3xI6i'><tr id='3xI6i'><dt id='3xI6i'><q id='3xI6i'><span id='3xI6i'><b id='3xI6i'><form id='3xI6i'><ins id='3xI6i'></ins><ul id='3xI6i'></ul><sub id='3xI6i'></sub></form><legend id='3xI6i'></legend><bdo id='3xI6i'><pre id='3xI6i'><center id='3xI6i'></center></pre></bdo></b><th id='3xI6i'></th></span></q></dt></tr></i><div id='3xI6i'><tfoot id='3xI6i'></tfoot><dl id='3xI6i'><fieldset id='3xI6i'></fieldset></dl></div>
            • <tfoot id='3xI6i'></tfoot>
              <legend id='3xI6i'><style id='3xI6i'><dir id='3xI6i'><q id='3xI6i'></q></dir></style></legend>

                • <bdo id='3xI6i'></bdo><ul id='3xI6i'></ul>
                  本文介绍了将元素插入到MongoDB中的嵌套数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有这个:

                  {
                    "_id" : ObjectId("4fb4fd04b748611ca8da0d48"),
                    "Name" : "Categories",
                    "categories" : [{
                        "_id" : ObjectId("4fb4fd04b748611ca8da0d46"),
                        "name" : "SubCategory",
                        "sub-categories" : [{
                            "_id" : ObjectId("4fb4fd04b748611ca8da0d47"),
                            "name" : "SubSubCategory",
                            "standards" : []
                          }]
                      }]
                  }
                  

                  我想使用 C# 驱动程序添加一个新的 SubCategory.有没有最佳的方法来做到这一点?

                  I would like to add a new SubCategory using the C# driver. Is there an optimal way to do this?

                  推荐答案

                  您可以使用 FindOneAndUpdateAsync 和位置运算符来做到这一点

                  You can do this using FindOneAndUpdateAsync and positional operator

                  public async Task Add(string productId, string categoryId, SubCategory newSubCategory)
                  {
                      var filter = Builders<Product>.Filter.And(
                           Builders<Product>.Filter.Where(x => x.Id == productId), 
                           Builders<Product>.Filter.Eq("Categories.Id", categoryId));
                      var update = Builders<Product>.Update.Push("Categories.$.SubCategories", newSubCategory);
                      await collection.FindOneAndUpdateAsync(filter, update);
                  }
                  

                  这篇关于将元素插入到MongoDB中的嵌套数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何按顺序将项目插入列表? 下一篇:如何在 mvc5 中使用 allowhtml 属性进行操作

                  相关文章

                  最新文章

                    • <bdo id='02Xua'></bdo><ul id='02Xua'></ul>

                    <i id='02Xua'><tr id='02Xua'><dt id='02Xua'><q id='02Xua'><span id='02Xua'><b id='02Xua'><form id='02Xua'><ins id='02Xua'></ins><ul id='02Xua'></ul><sub id='02Xua'></sub></form><legend id='02Xua'></legend><bdo id='02Xua'><pre id='02Xua'><center id='02Xua'></center></pre></bdo></b><th id='02Xua'></th></span></q></dt></tr></i><div id='02Xua'><tfoot id='02Xua'></tfoot><dl id='02Xua'><fieldset id='02Xua'></fieldset></dl></div>

                  1. <tfoot id='02Xua'></tfoot>
                    1. <legend id='02Xua'><style id='02Xua'><dir id='02Xua'><q id='02Xua'></q></dir></style></legend>

                      <small id='02Xua'></small><noframes id='02Xua'>