<legend id='jyyHv'><style id='jyyHv'><dir id='jyyHv'><q id='jyyHv'></q></dir></style></legend>

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

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

        Spring mongo 存储库切片

        Spring mongo repository slice(Spring mongo 存储库切片)

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

              <tbody id='H9xTj'></tbody>
              <bdo id='H9xTj'></bdo><ul id='H9xTj'></ul>

            • <tfoot id='H9xTj'></tfoot>

                  <legend id='H9xTj'><style id='H9xTj'><dir id='H9xTj'><q id='H9xTj'></q></dir></style></legend>

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

                  本文介绍了Spring mongo 存储库切片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在将 spring-sata-mongodb 1.8.2 与 MongoRepository 一起使用,并且我尝试在查询时使用 mongo $slice 选项来限制列表大小,但我在 mongorepository 中找不到此选项.

                  I am using spring-sata-mongodb 1.8.2 with MongoRepository and I am trying to use the mongo $slice option to limit a list size when query, but I can't find this option in the mongorepository.

                  我的课程如下所示:

                  public class InnerField{
                      public String a;
                      public String b;
                      public int n;
                  }
                  
                  @Document(collection="Record")
                  punlic class Record{
                      public ObjectId id;
                      public List<InnerField> fields;
                      public int numer;
                  }
                  

                  如您所见,我有一个集合名称Record",文档包含 InnerField.InnerField 列表一直在增长,所以我想在查询时限制所选字段的数量.

                  As you can see I have one collection name "Record" and the document contains the InnerField. the InnerField list is growing all the time so i want to limit the number of the selected fields when I am querying.

                  我看到了:https://docs.mongodb.org/v3.0/tutorial/project-fields-from-query-results/

                  这正是我需要的,但我在 mongorepository 中找不到相关参考.

                  which is exactly what I need but I couldn't find the relevant reference in mongorepository.

                  有什么想法吗?

                  推荐答案

                  使用 Java Mongo 驱动程序中提供的切片功能,使用投影,如下代码所示.

                  Use slice functionality as provided in Java Mongo driver using projection as in below code.

                  例如:

                  List<Entity> list = new ArrayList<Entity>();
                          // Return the last 10 weeks data only
                  FindIterable<Document> list = db.getDBCollection("COLLECTION").find()
                                  .projection(Projections.fields(Projections.slice("count", -10)));
                  MongoCursor<Document> doc = list.iterator();
                  while(doc.hasNext()){
                      list.add(new Gson().fromJson(doc.next().toJson(), Entity.class));
                  }
                  

                  上述查询将获取所有实体类类型的文档,并且每个实体类文档的字段"列表将只有最后 10 条记录.

                  The above query will fetch all documents of type Entity class and the "field" list of each Entity class document will have only last 10 records.

                  这篇关于Spring mongo 存储库切片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

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

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

                              <tbody id='HFnbk'></tbody>