@@ -1209,7 +1209,7 @@ public function getDocument(Document $collection, string $id, array $queries = [
12091209 $ document = $ this ->castingAfter ($ collection , $ document );
12101210
12111211 // Ensure missing relationship attributes are set to null (MongoDB doesn't store null fields)
1212- if (! empty ($ projections )) {
1212+ if (empty ($ projections )) {
12131213 $ this ->ensureRelationshipDefaults ($ collection , $ document );
12141214 }
12151215
@@ -2215,7 +2215,7 @@ public function find(
22152215 }
22162216
22172217 // Ensure missing relationship attributes are set to null (MongoDB doesn't store null fields)
2218- if (! empty ($ projections )) {
2218+ if (empty ($ projections )) {
22192219 foreach ($ found as $ document ) {
22202220 $ this ->ensureRelationshipDefaults ($ collection , $ document );
22212221 }
@@ -2311,15 +2311,10 @@ public function count(QueryContext $context, ?int $max, array $filters, array $j
23112311 // Escape query attribute names that contain dots and match collection attributes
23122312 $ this ->escapeQueryAttributes ($ collection , $ filters );
23132313
2314- $ filters = [];
23152314 $ options = [];
23162315
23172316 if (!\is_null ($ max ) && $ max > 0 ) {
2318- $ options ['limit ' ] = $ max ;
2319- }
2320-
2321- if ($ this ->timeout ) {
2322- $ options ['maxTimeMS ' ] = $ this ->timeout ;
2317+ //$options['limit'] = $max; todo: Remove if not needed
23232318 }
23242319
23252320 // Build filters from queries
@@ -2362,14 +2357,14 @@ public function count(QueryContext $context, ?int $max, array $filters, array $j
23622357 }
23632358
23642359 // Add limit stage if specified
2365- if (!\is_null ($ max )) {
2360+ if (!\is_null ($ max ) && $ max > 0 ) {
23662361 $ pipeline [] = ['$limit ' => $ max ];
23672362 }
23682363
23692364 // Use $group and $sum when limit is specified, $count when no limit
23702365 // Note: $count stage doesn't works well with $limit in the same pipeline
23712366 // When limit is specified, we need to use $group + $sum to count the limited documents
2372- if (!\is_null ($ max )) {
2367+ if (!\is_null ($ max ) && $ max > 0 ) {
23732368 // When limit is specified, use $group and $sum to count limited documents
23742369 $ pipeline [] = [
23752370 '$group ' => [
0 commit comments