This repository was archived by the owner on Feb 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 7
7
use MongoDB \BSON \Regex ;
8
8
use MongoDB \BSON \Type ;
9
9
use MongoDB \Builder \Query \RegexOperator ;
10
+ use MongoDB \Builder \Query \TypeOperator ;
10
11
use MongoDB \Builder \Type \CombinedFieldQuery ;
11
12
use MongoDB \Builder \Type \FieldQueryInterface ;
12
13
use MongoDB \Builder \Type \QueryInterface ;
@@ -25,6 +26,27 @@ final class Query
25
26
{
26
27
use Query \FactoryTrait {
27
28
regex as private generatedRegex;
29
+ type as private generatedType;
30
+ }
31
+
32
+ /**
33
+ * Selects documents if a field is of the specified type.
34
+ *
35
+ * @see https://www.mongodb.com/docs/manual/reference/operator/query/type/
36
+ *
37
+ * @param int|non-empty-string|QueryType ...$type
38
+ *
39
+ * @no-named-arguments
40
+ */
41
+ public static function type (string |int |QueryType ...$ type ): TypeOperator
42
+ {
43
+ foreach ($ type as &$ value ) {
44
+ if ($ value instanceof QueryType) {
45
+ $ value = $ value ->value ;
46
+ }
47
+ }
48
+
49
+ return self ::generatedType (...$ type );
28
50
}
29
51
30
52
/**
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ public function testQueryingByDataType(): void
39
39
zipCode: Query::type (1 ),
40
40
),
41
41
Stage::match (
42
- zipCode: Query::type (' double ' ),
42
+ zipCode: Query::type (QueryType::Double ),
43
43
),
44
44
Stage::match (
45
45
zipCode: QueryType::Number,
@@ -70,7 +70,7 @@ public function testQueryingByMultipleDataType(): void
70
70
zipCode: Query::type (2 , 1 ),
71
71
),
72
72
Stage::match (
73
- zipCode: Query::type (' string ' , 'double ' ),
73
+ zipCode: Query::type (QueryType::String , 'double ' ),
74
74
),
75
75
);
76
76
You can’t perform that action at this time.
0 commit comments