• <legend id='5uMXN'><style id='5uMXN'><dir id='5uMXN'><q id='5uMXN'></q></dir></style></legend>

    <small id='5uMXN'></small><noframes id='5uMXN'>

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

    1. <tfoot id='5uMXN'></tfoot>

          <bdo id='5uMXN'></bdo><ul id='5uMXN'></ul>

      1. 使用 Spring Data MongoRepository 进行更新查询的自定义方法

        时间:2024-08-23

          <i id='nRtS2'><tr id='nRtS2'><dt id='nRtS2'><q id='nRtS2'><span id='nRtS2'><b id='nRtS2'><form id='nRtS2'><ins id='nRtS2'></ins><ul id='nRtS2'></ul><sub id='nRtS2'></sub></form><legend id='nRtS2'></legend><bdo id='nRtS2'><pre id='nRtS2'><center id='nRtS2'></center></pre></bdo></b><th id='nRtS2'></th></span></q></dt></tr></i><div id='nRtS2'><tfoot id='nRtS2'></tfoot><dl id='nRtS2'><fieldset id='nRtS2'></fieldset></dl></div>
            <tbody id='nRtS2'></tbody>
            <tfoot id='nRtS2'></tfoot>
            • <small id='nRtS2'></small><noframes id='nRtS2'>

              <legend id='nRtS2'><style id='nRtS2'><dir id='nRtS2'><q id='nRtS2'></q></dir></style></legend>
                  <bdo id='nRtS2'></bdo><ul id='nRtS2'></ul>

                  本文介绍了使用 Spring Data MongoRepository 进行更新查询的自定义方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 org.springframework.data.mongodb.repository.MongoRepository.我写了一些自定义方法,如下所示,

                  I am using org.springframework.data.mongodb.repository.MongoRepository. I have written some custom method like below,

                  public interface DocRepository extends MongoRepository<Doc, String> {
                       Doc findByDocIdAndAssignmentId(final String docId, final String assignemtId);
                  }
                  

                  如何编写一个自定义方法,在满足条件时更新所有条目.

                  How can I write a custom method which update all entries when meeting a criteria.

                  例如,如果分配 id 为xyz",则将文档倾斜字段设置为abc"?

                  For example set document tilte field to "abc" if assignment id is "xyz"?

                  推荐答案

                  1) 您需要创建接口,例如 CustomDocRepository 并将此接口添加为您的 DocRepository 的 Base:

                  1) You need to create inteface e.g CustomDocRepository and add this interfaces as Base for your DocRepository:

                  public interface DocRepository extends MongoRepository<Doc, String>, CustomDocRepository {
                  
                      void updateDocumentTitle(String id, String title);
                  
                  }
                  

                  2) 您需要为 DocRepository 添加实现:

                  2) You need to add implementation for the DocRepository:

                  @Repository
                  public class CustomDocRepositoryImpl implements DocRepository {
                    @Autowired
                    private MongoTemplate mongoTemplate;
                  
                  
                  @Override
                  public void updateDocumentTitle(String id, String title) {
                      Query query = new Query().addCriteria(where("_id").is(id));
                  
                      Update update = new Update();
                      update.set("title", title);
                      mongoTemplate.update(Doc.class).matching(query).apply(update).first();
                  }
                  }
                  

                  这就是你需要做的一切

                  这篇关于使用 Spring Data MongoRepository 进行更新查询的自定义方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Spring Data Mongo:如何按其字段返回嵌套对象? 下一篇:Spring Data REST:MongoDB 存储库的自定义查询

                  相关文章

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

                    <tfoot id='bMZUM'></tfoot>
                  1. <legend id='bMZUM'><style id='bMZUM'><dir id='bMZUM'><q id='bMZUM'></q></dir></style></legend>
                    1. <small id='bMZUM'></small><noframes id='bMZUM'>