@@ -74,17 +74,73 @@ def test_covering_json_index(self):
74
74
self .assertEqual (resp ["execution_stats" ]["results_returned" ], 3 )
75
75
76
76
def test_reporting_consistency (self ):
77
- resp = self .db .find (
78
- {"age" : {"$lte" : 42 }},
79
- fields = ["name" , "email" , "age" ],
80
- limit = 3 ,
81
- return_raw = True ,
82
- executionStats = True ,
83
- )
84
- executionStats = resp ["execution_stats" ]
85
- self .assertEqual (executionStats ["total_keys_examined" ], 3 )
86
- self .assertEqual (executionStats ["total_docs_examined" ], 3 )
87
- self .assertEqual (executionStats ["results_returned" ], 3 )
77
+ cases = [
78
+ {
79
+ "title" : "with limit" ,
80
+ "selector" : {"age" : {"$lte" : 42 }},
81
+ "fields" : ["name" , "email" , "age" ],
82
+ "limit" : 3 ,
83
+ "total_keys_examined" : 3 ,
84
+ "total_docs_examined" : 3 ,
85
+ "results_returned" : 3 ,
86
+ },
87
+ {
88
+ "title" : "partial matches" ,
89
+ "selector" : {"favorites" : {"$elemMatch" : {"$eq" : "Erlang" }}},
90
+ "fields" : ["name" , "email" , "twitter" ],
91
+ "limit" : 200 ,
92
+ "total_keys_examined" : 15 ,
93
+ "total_docs_examined" : 15 ,
94
+ "results_returned" : 6 ,
95
+ },
96
+ {
97
+ "title" : "no matches, using _all_docs" ,
98
+ "selector" : {"foo" : "bar" },
99
+ "fields" : [],
100
+ "limit" : 200 ,
101
+ "total_keys_examined" : 25 ,
102
+ "total_docs_examined" : 25 ,
103
+ "results_returned" : 0 ,
104
+ },
105
+ {
106
+ "title" : "no matches, indexed column (no keys examined)" ,
107
+ "selector" : {"name.first" : "Lee" , "name.last" : "Jackson" },
108
+ "fields" : ["email" , "twitter" ],
109
+ "limit" : 200 ,
110
+ "total_keys_examined" : 0 ,
111
+ "total_docs_examined" : 0 ,
112
+ "results_returned" : 0 ,
113
+ },
114
+ {
115
+ "title" : "no matches, indexed column" ,
116
+ "selector" : {"favorites" : {"$elemMatch" : {"$eq" : "Haskell" }}},
117
+ "fields" : ["name" , "email" , "twitter" ],
118
+ "limit" : 200 ,
119
+ "total_keys_examined" : 15 ,
120
+ "total_docs_examined" : 15 ,
121
+ "results_returned" : 0 ,
122
+ },
123
+ ]
124
+
125
+ for case in cases :
126
+ with self .subTest (scenario = case ["title" ]):
127
+ resp = self .db .find (
128
+ case ["selector" ],
129
+ fields = case ["fields" ],
130
+ limit = case ["limit" ],
131
+ return_raw = True ,
132
+ executionStats = True ,
133
+ )
134
+ executionStats = resp ["execution_stats" ]
135
+ self .assertEqual (
136
+ executionStats ["total_keys_examined" ], case ["total_keys_examined" ]
137
+ )
138
+ self .assertEqual (
139
+ executionStats ["total_docs_examined" ], case ["total_docs_examined" ]
140
+ )
141
+ self .assertEqual (
142
+ executionStats ["results_returned" ], case ["results_returned" ]
143
+ )
88
144
89
145
90
146
@unittest .skipUnless (mango .has_text_service (), "requires text service" )
0 commit comments