Skip to content

Commit 7800067

Browse files
feat(NODE-6676): add support for nsType in change stream create events (#4431)
Co-authored-by: Neal Beeken <[email protected]>
1 parent 8ab1155 commit 7800067

File tree

3 files changed

+238
-0
lines changed

3 files changed

+238
-0
lines changed

src/change_stream.ts

+7
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,13 @@ export interface ChangeStreamCreateDocument
419419
ChangeStreamDocumentCollectionUUID {
420420
/** Describes the type of operation represented in this change notification */
421421
operationType: 'create';
422+
423+
/**
424+
* The type of the newly created object.
425+
*
426+
* @sinceServerVersion 8.1.0
427+
*/
428+
nsType?: 'collection' | 'timeseries' | 'view';
422429
}
423430

424431
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
{
2+
"description": "change-streams-nsType",
3+
"schemaVersion": "1.7",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "8.1.0",
7+
"topologies": [
8+
"replicaset",
9+
"sharded"
10+
],
11+
"serverless": "forbid"
12+
}
13+
],
14+
"createEntities": [
15+
{
16+
"client": {
17+
"id": "client0",
18+
"useMultipleMongoses": false
19+
}
20+
},
21+
{
22+
"database": {
23+
"id": "database0",
24+
"client": "client0",
25+
"databaseName": "database0"
26+
}
27+
}
28+
],
29+
"tests": [
30+
{
31+
"description": "nsType is present when creating collections",
32+
"operations": [
33+
{
34+
"name": "dropCollection",
35+
"object": "database0",
36+
"arguments": {
37+
"collection": "foo"
38+
}
39+
},
40+
{
41+
"name": "createChangeStream",
42+
"object": "database0",
43+
"arguments": {
44+
"pipeline": [],
45+
"showExpandedEvents": true
46+
},
47+
"saveResultAsEntity": "changeStream0"
48+
},
49+
{
50+
"name": "createCollection",
51+
"object": "database0",
52+
"arguments": {
53+
"collection": "foo"
54+
}
55+
},
56+
{
57+
"name": "iterateUntilDocumentOrError",
58+
"object": "changeStream0",
59+
"expectResult": {
60+
"operationType": "create",
61+
"nsType": "collection"
62+
}
63+
}
64+
]
65+
},
66+
{
67+
"description": "nsType is present when creating timeseries",
68+
"operations": [
69+
{
70+
"name": "dropCollection",
71+
"object": "database0",
72+
"arguments": {
73+
"collection": "foo"
74+
}
75+
},
76+
{
77+
"name": "createChangeStream",
78+
"object": "database0",
79+
"arguments": {
80+
"pipeline": [],
81+
"showExpandedEvents": true
82+
},
83+
"saveResultAsEntity": "changeStream0"
84+
},
85+
{
86+
"name": "createCollection",
87+
"object": "database0",
88+
"arguments": {
89+
"collection": "foo",
90+
"timeseries": {
91+
"timeField": "time",
92+
"metaField": "meta",
93+
"granularity": "minutes"
94+
}
95+
}
96+
},
97+
{
98+
"name": "iterateUntilDocumentOrError",
99+
"object": "changeStream0",
100+
"expectResult": {
101+
"operationType": "create",
102+
"nsType": "timeseries"
103+
}
104+
}
105+
]
106+
},
107+
{
108+
"description": "nsType is present when creating views",
109+
"operations": [
110+
{
111+
"name": "dropCollection",
112+
"object": "database0",
113+
"arguments": {
114+
"collection": "foo"
115+
}
116+
},
117+
{
118+
"name": "createChangeStream",
119+
"object": "database0",
120+
"arguments": {
121+
"pipeline": [],
122+
"showExpandedEvents": true
123+
},
124+
"saveResultAsEntity": "changeStream0"
125+
},
126+
{
127+
"name": "createCollection",
128+
"object": "database0",
129+
"arguments": {
130+
"collection": "foo",
131+
"viewOn": "testName"
132+
}
133+
},
134+
{
135+
"name": "iterateUntilDocumentOrError",
136+
"object": "changeStream0",
137+
"expectResult": {
138+
"operationType": "create",
139+
"nsType": "view"
140+
}
141+
}
142+
]
143+
}
144+
]
145+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
description: "change-streams-nsType"
2+
schemaVersion: "1.7"
3+
runOnRequirements:
4+
- minServerVersion: "8.1.0"
5+
topologies: [ replicaset, sharded ]
6+
serverless: forbid
7+
createEntities:
8+
- client:
9+
id: &client0 client0
10+
useMultipleMongoses: false
11+
- database:
12+
id: &database0 database0
13+
client: *client0
14+
databaseName: *database0
15+
16+
tests:
17+
- description: "nsType is present when creating collections"
18+
operations:
19+
- name: dropCollection
20+
object: *database0
21+
arguments:
22+
collection: &collection0 foo
23+
- name: createChangeStream
24+
object: *database0
25+
arguments:
26+
pipeline: []
27+
showExpandedEvents: true
28+
saveResultAsEntity: &changeStream0 changeStream0
29+
- name: createCollection
30+
object: *database0
31+
arguments:
32+
collection: *collection0
33+
- name: iterateUntilDocumentOrError
34+
object: *changeStream0
35+
expectResult:
36+
operationType: create
37+
nsType: collection
38+
39+
- description: "nsType is present when creating timeseries"
40+
operations:
41+
- name: dropCollection
42+
object: *database0
43+
arguments:
44+
collection: &collection0 foo
45+
- name: createChangeStream
46+
object: *database0
47+
arguments:
48+
pipeline: []
49+
showExpandedEvents: true
50+
saveResultAsEntity: &changeStream0 changeStream0
51+
- name: createCollection
52+
object: *database0
53+
arguments:
54+
collection: *collection0
55+
timeseries:
56+
timeField: "time"
57+
metaField: "meta"
58+
granularity: "minutes"
59+
- name: iterateUntilDocumentOrError
60+
object: *changeStream0
61+
expectResult:
62+
operationType: create
63+
nsType: timeseries
64+
65+
- description: "nsType is present when creating views"
66+
operations:
67+
- name: dropCollection
68+
object: *database0
69+
arguments:
70+
collection: &collection0 foo
71+
- name: createChangeStream
72+
object: *database0
73+
arguments:
74+
pipeline: []
75+
showExpandedEvents: true
76+
saveResultAsEntity: &changeStream0 changeStream0
77+
- name: createCollection
78+
object: *database0
79+
arguments:
80+
collection: *collection0
81+
viewOn: testName
82+
- name: iterateUntilDocumentOrError
83+
object: *changeStream0
84+
expectResult:
85+
operationType: create
86+
nsType: view

0 commit comments

Comments
 (0)