This repository was archived by the owner on Feb 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +235
-0
lines changed
generator/config/expression Expand file tree Collapse file tree 5 files changed +235
-0
lines changed Original file line number Diff line number Diff line change @@ -12,3 +12,28 @@ arguments:
12
12
name : expression
13
13
type :
14
14
- resolvesToTimestamp
15
+ tests :
16
+ -
17
+ name : ' Obtain the Incrementing Ordinal from a Timestamp Field'
18
+ link : ' https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsIncrement/#obtain-the-incrementing-ordinal-from-a-timestamp-field'
19
+ pipeline :
20
+ -
21
+ $project :
22
+ _id : 0
23
+ saleTimestamp : 1
24
+ saleIncrement :
25
+ $tsIncrement : ' $saleTimestamp'
26
+ -
27
+ name : ' Use $tsSecond in a Change Stream Cursor to Monitor Collection Changes'
28
+ link : ' https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/#use--tssecond-in-a-change-stream-cursor-to-monitor-collection-changes'
29
+ pipeline :
30
+ -
31
+ $match :
32
+ $expr :
33
+ $eq :
34
+ -
35
+ $mod :
36
+ -
37
+ $tsIncrement : ' $clusterTime'
38
+ - 2
39
+ - 0
Original file line number Diff line number Diff line change @@ -12,3 +12,22 @@ arguments:
12
12
name : expression
13
13
type :
14
14
- resolvesToTimestamp
15
+ tests :
16
+ -
17
+ name : ' Obtain the Number of Seconds from a Timestamp Field'
18
+ link : ' https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/#obtain-the-number-of-seconds-from-a-timestamp-field'
19
+ pipeline :
20
+ -
21
+ $project :
22
+ _id : 0
23
+ saleTimestamp : 1
24
+ saleSeconds :
25
+ $tsSecond : ' $saleTimestamp'
26
+ -
27
+ name : ' Use $tsSecond in a Change Stream Cursor to Monitor Collection Changes'
28
+ link : ' https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/#use--tssecond-in-a-change-stream-cursor-to-monitor-collection-changes'
29
+ pipeline :
30
+ -
31
+ $addFields :
32
+ clusterTimeSeconds :
33
+ $tsSecond : ' $clusterTime'
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace MongoDB \Tests \Builder \Expression ;
6
+
7
+ use MongoDB \Builder \Expression ;
8
+ use MongoDB \Builder \Pipeline ;
9
+ use MongoDB \Builder \Query ;
10
+ use MongoDB \Builder \Stage ;
11
+ use MongoDB \Tests \Builder \PipelineTestCase ;
12
+
13
+ /**
14
+ * Test $tsIncrement expression
15
+ */
16
+ class TsIncrementOperatorTest extends PipelineTestCase
17
+ {
18
+ public function testObtainTheIncrementingOrdinalFromATimestampField (): void
19
+ {
20
+ $ pipeline = new Pipeline (
21
+ Stage::project (
22
+ _id: 0 ,
23
+ saleTimestamp: 1 ,
24
+ saleIncrement: Expression::tsIncrement (
25
+ Expression::timestampFieldPath ('saleTimestamp ' ),
26
+ ),
27
+ ),
28
+ );
29
+
30
+ $ this ->assertSamePipeline (Pipelines::TsIncrementObtainTheIncrementingOrdinalFromATimestampField, $ pipeline );
31
+ }
32
+
33
+ public function testUseTsSecondInAChangeStreamCursorToMonitorCollectionChanges (): void
34
+ {
35
+ $ pipeline = new Pipeline (
36
+ Stage::match (
37
+ Query::expr (
38
+ Expression::eq (
39
+ Expression::mod (
40
+ Expression::tsIncrement (
41
+ Expression::timestampFieldPath ('clusterTime ' ),
42
+ ),
43
+ 2 ,
44
+ ),
45
+ 0 ,
46
+ ),
47
+ ),
48
+ ),
49
+ );
50
+
51
+ $ this ->assertSamePipeline (Pipelines::TsIncrementUseTsSecondInAChangeStreamCursorToMonitorCollectionChanges, $ pipeline );
52
+ }
53
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace MongoDB \Tests \Builder \Expression ;
6
+
7
+ use MongoDB \Builder \Expression ;
8
+ use MongoDB \Builder \Pipeline ;
9
+ use MongoDB \Builder \Stage ;
10
+ use MongoDB \Tests \Builder \PipelineTestCase ;
11
+
12
+ /**
13
+ * Test $tsSecond expression
14
+ */
15
+ class TsSecondOperatorTest extends PipelineTestCase
16
+ {
17
+ public function testObtainTheNumberOfSecondsFromATimestampField (): void
18
+ {
19
+ $ pipeline = new Pipeline (
20
+ Stage::project (
21
+ _id: 0 ,
22
+ saleTimestamp: 1 ,
23
+ saleSeconds: Expression::tsSecond (
24
+ Expression::timestampFieldPath ('saleTimestamp ' ),
25
+ ),
26
+ ),
27
+ );
28
+
29
+ $ this ->assertSamePipeline (Pipelines::TsSecondObtainTheNumberOfSecondsFromATimestampField, $ pipeline );
30
+ }
31
+
32
+ public function testUseTsSecondInAChangeStreamCursorToMonitorCollectionChanges (): void
33
+ {
34
+ $ pipeline = new Pipeline (
35
+ Stage::addFields (
36
+ clusterTimeSeconds: Expression::tsSecond (
37
+ Expression::timestampFieldPath ('clusterTime ' ),
38
+ ),
39
+ ),
40
+ );
41
+
42
+ $ this ->assertSamePipeline (Pipelines::TsSecondUseTsSecondInAChangeStreamCursorToMonitorCollectionChanges, $ pipeline );
43
+ }
44
+ }
You can’t perform that action at this time.
0 commit comments