亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么 Spring Data MongoDB 不提供聚合操作的“提示”選項,mongodb

為什么 Spring Data MongoDB 不提供聚合操作的“提示”選項,mongodb

偶然的你 2023-03-31 16:42:40
我經常使用 MongoTemplate 進行聚合操作,但效率不高。我想“提示”指定我自己的索引來提高性能但是AggregationOptions中不能添加“hint”選項我看到 DBCollection 可能能夠執行此操作,但我沒有找到執行此操作的方法。AggregateOperation 不是 DBCollection 聚合方法中的參數,AggregateOperation 是我能找到的唯一可以使用“提示”的地方mongodb version is4.0.4Spring-data-mongodb version is 2.1.4The mongodb-driver version is 3.8.2JDK 111.org.springframework.data.mongodb.core.aggregation.AggregationOption可用參數:public AggregationOptions(boolean allowDiskUse, boolean explain, @Nullable Document cursor,            @Nullable Collation collation) {        this.allowDiskUse = allowDiskUse;        this.explain = explain;        this.cursor = Optional.ofNullable(cursor);        this.collation = Optional.ofNullable(collation);    }2.com.mongodb.AggregationOptions可用參數:AggregationOptions(AggregationOptions.Builder builder) {        this.batchSize = builder.batchSize;        this.allowDiskUse = builder.allowDiskUse;        this.outputMode = builder.outputMode;        this.maxTimeMS = builder.maxTimeMS;        this.bypassDocumentValidation = builder.bypassDocumentValidation;        this.collation = builder.collation;    }我只是想通過索引提高查詢效率。查詢速度太慢。一個復雜的查詢需要 20 秒。簡單查詢也需要4~5s。英文不是很好,表達不清楚請見諒。
查看完整描述

1 回答

?
波斯汪

TA貢獻1811條經驗 獲得超4個贊

AggregationOption中的提示是最近實現的[SpringDataMongoDB Release 3.1],你可以像這樣使用它


    Aggregation

      .newAggregation(aggrgationOperations)

      .withOptions(AggregationOptions.builder().hint(new Document("fieldName", 1)).build()

或者對于 geoSpatial 查詢,只需將索引更改為位置字段,如:


AggregationOptions.builder().hint(new Document("fieldName", "2dsphere").build();


查看完整回答
反對 回復 2023-03-31
  • 1 回答
  • 0 關注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號