Home > database >  Boot integrates MongoTemplate, very slow when the count method with conditions, solve?
Boot integrates MongoTemplate, very slow when the count method with conditions, solve?

Time:10-09

On the first code:



Data volume probably around 1600 w,

Case 1: do not add any conditions
Count the total number: 16907883
Count running time: 4 ms
Find the total number: 10
Find running time: 8 ms
13 ms
all running time.
Situation 2: add period conditions under the condition of

Directing the find start Query: {" $" and ": [{" createTime" : {" $gte ": {" $date" : 1595952000000}}}, {" createTime ": {" $lte" : {" $date ": 1596470400000}}}]}, Fields: Sort: {} {},


Count the total number: 10993965
Count running time: 22470 ms
Find the total number: 10
Find running time: 9 ms
All running time: 22482 ms

Description: createTime field is added index

Case 3: according to the results of full text indexing query, the circumstances of less data
Directing the find start Query: {" $text ": {" $search" : "111"}}, Fields: {}, Sort: {}

Count the total number: 53
Count running time: 153 ms
Find the total number: 10
Find running time: 6 ms
All running time: 161 ms


Situation 4: according to the full-text index field queries, data more (almost millions)
the condition of the
Directing the find start Query: {" $text ": {" $search" : "1"}}, Fields: {}, Sort: {}

Wait too long, not statistical



Question:
1, the count method is very time-consuming when combined with conditions, index because no go??
Because it is a time query so using the following conditions in the form of assembling,
Criteria. AndOperator (
The criteria. The where (filedBtwBegin. Replace (" _begin ", "")). The gte (filedBtwBeginValue),
The criteria. The where (filedBtwEnd. Replace (" _end ", "")), lte (filedBtwEndValue)
);
2, add the full-text index field collection, caught in the large amount of data is very slow, what method can be optimized?? The full-text index in effect and can query the data through the rules of the full-text index, but is very slow

3, because the project was a page, so if the data quantity is large, when the point to the last page, sometimes very, very card, but this has nothing to do with the count method, and paging query slow

Consult everybody to give directions, thank you