Spring Data Mongo DB:回复消息長度5502322小於最大消息長度 (Spring Data Mongo DB: The reply message length 5502322 is less than the maximum message length)


問題描述

Spring Data Mongo DB:回复消息長度5502322小於最大消息長度 (Spring Data Mongo DB: The reply message length 5502322 is less than the maximum message length)

代碼:

接口::

@Query(value = "{'status': {$in: ?0} , 'date':{ $lte: ?1 }}")
List<Blog> findByStatusAndCurrentDateWithOrdering(List<String> status, Date date, Sort order);

調用類:

findByStatusAndCurrentDateWithOrdering(status, new Date(), Sort.by(Direction.DESC, "date")

Azure中部署的應用程序出錯:

"status": 500,
    "error": "Internal Server Error",
    "message": "The reply message length 5502322 is less than the maximum message length 4194304; nested exception is com.mongodb.MongoIn
ternalException: The reply message length 5502322 is less than the maximum message length 4194304",

The MongoDB 中的內容包括 Base64 Image 以及 ID、HTML。(並且只有 11 或 12 行)

客戶的 Azure Mongo DB 版本是 <3.2.0。而在本地它是 > 3.2

上面的代碼可以做哪些改變來分塊讀取或限制它的工作?


參考解法

方法 1:

You need to change to this:

db.blog.aggregate([
    {$match:{"status": {$in: status} , "date":{ $lte: date }}},
    {$sort:{"date":‑1}}
],{allowDiskUse:true})

Edit:

import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
...

//Inside your `@Service` class, include:
@Autowired
private MongoTemplate mongotemplate;
...

MatchOperation filter = match(Criteria.where("status").in(status).and("date").lte(date));
SortOperation sort    = sort(Direction.DESC, "date")

Aggregation aggregation = newAggregation(filter, sort)
                             .withOptions(newAggregationOptions()
                             .allowDiskUse(true).build());
AggregationResults<Blog> result = mongoTemplate.aggregate(aggregation, mongoTemplate.getCollection(Blog.class), Blog.class);
List<Blog> blogs = result.getMappedResults();

(by fatherazraelValijon)

參考文件

  1. Spring Data Mongo DB: The reply message length 5502322 is less than the maximum message length (CC BY‑SA 2.5/3.0/4.0)

#spring-data-mongodb #azure #mongoDB






相關問題

如何在 mongodb 中保存 java.sql.date 對象? (How to save java.sql.date object in mongodb?)

Spring Data MongoDB Core 1.9.1.RELEASE 給出 java.lang.NoClassDefFoundError: org/springframework/data/geo/GeoResults (Spring Data MongoDB Core 1.9.1.RELEASE gives java.lang.NoClassDefFoundError: org/springframework/data/geo/GeoResults)

我可以結合 AND 和 OR 條件嗎 (Can I combine AND and OR conditions)

查詢數據時應該使用 MongoTemplate 還是 DBCollection (Should i use MongoTemplate or DBCollection when query data)

是否有可能使用 Spring Data MongoDb 來定義自定義標準? (Is possibility using Spring Data MongoDb to define custom Criteria?)

Spring-data 2.1 使用 kotlin 獲取“UnsupportedOperationException:沒有訪問器設置屬性” (Spring-data 2.1 get "UnsupportedOperationException: No accessor to set property" with kotlin)

調用頁面大小大於 36 的 Spring Data MongoDB 存儲庫方法時出現 StackOverflowError (StackOverflowError when calling Spring Data MongoDB repository method with a page size bigger than 36)

JSON- MongoDB 中帶有 Spring Data 的數組 (JSON- Array in MongoDB with Spring Data)

Spring Data Mongo DB:回复消息長度5502322小於最大消息長度 (Spring Data Mongo DB: The reply message length 5502322 is less than the maximum message length)

Spring Boot 反應式和 mongodb '命令插入需要身份驗證' (Spring boot reactive and mongodb 'command insert requires authentication')

使用 MongoDB Spring Data Aggregation 匹配日期時間字段的問題 (Problem with matching date-time fields using MongoDB Spring Data Aggregation)

在 Spring Boot 應用程序中實現工作進程 (Implementing worker processes in a Spring Boot application)







留言討論