Skip to content

Commit 67d7bab

Browse files
fix(NODE-5745): ignore Read/Write Concern in Atlas Search Index Helpers (#4042)
1 parent 3a0e011 commit 67d7bab

File tree

5 files changed

+468
-1
lines changed

5 files changed

+468
-1
lines changed

src/collection.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,7 @@ export class Collection<TSchema extends Document = Document> {
10741074
): ListSearchIndexesCursor {
10751075
options =
10761076
typeof indexNameOrOptions === 'object' ? indexNameOrOptions : options == null ? {} : options;
1077+
10771078
const indexName =
10781079
indexNameOrOptions == null
10791080
? null

src/cursor/list_search_indexes_cursor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { AggregateOptions } from '../operations/aggregate';
33
import { AggregationCursor } from './aggregation_cursor';
44

55
/** @public */
6-
export type ListSearchIndexesOptions = AggregateOptions;
6+
export type ListSearchIndexesOptions = Omit<AggregateOptions, 'readConcern' | 'writeConcern'>;
77

88
/** @public */
99
export class ListSearchIndexesCursor extends AggregationCursor<{ name: string }> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { expect } from 'chai';
2+
3+
import { type Collection, type CommandStartedEvent, type MongoClient } from '../../mongodb';
4+
5+
describe('Search Index Management Integration Tests', function () {
6+
describe('read concern and write concern ', function () {
7+
let client: MongoClient;
8+
let collection: Collection;
9+
let commandStartedEvents: CommandStartedEvent[];
10+
11+
beforeEach(async function () {
12+
client = this.configuration.newClient({}, { monitorCommands: true });
13+
await client.connect();
14+
collection = client.db('client').collection('searchIndexManagement');
15+
commandStartedEvents = [];
16+
client.on('commandStarted', e => commandStartedEvents.push(e));
17+
});
18+
19+
afterEach(async function () {
20+
await client.close();
21+
});
22+
23+
context('when listSearchIndexes operation is run with causalConsistency', function () {
24+
it('should not include write concern or read concern in command', {
25+
metadata: {
26+
requires: {
27+
topology: '!single',
28+
mongodb: '>=7.0',
29+
serverless: 'forbid'
30+
}
31+
},
32+
test: async function () {
33+
await client.withSession({ causalConsistency: true }, async session => {
34+
const res = collection.listSearchIndexes({ session });
35+
await res.toArray().catch(e => expect(e.errmsg).to.match(/^.*Atlas.*$/));
36+
expect(commandStartedEvents[0]).to.exist;
37+
expect(commandStartedEvents[0]?.command?.readConcern).to.not.exist;
38+
expect(commandStartedEvents[0]?.command?.writeConcern).to.not.exist;
39+
});
40+
}
41+
});
42+
});
43+
44+
context('when listSearchIndexes operation is run with snapshot on', function () {
45+
// TODO(NODE-6047): Ignore read/write concern in applySession for Atlas Search Index Helpers
46+
it('should include write concern or read concern in command - TODO(NODE-6047)', {
47+
metadata: {
48+
requires: {
49+
topology: ['replicaset', 'sharded'],
50+
mongodb: '>=7.0',
51+
serverless: 'forbid'
52+
}
53+
},
54+
test: async function () {
55+
await client.withSession({ snapshot: true }, async session => {
56+
const res = collection.listSearchIndexes({ session });
57+
const error = await res.toArray().catch(e => e);
58+
expect(error.errmsg).to.match(/^.*snapshot.*$/);
59+
expect(commandStartedEvents[0]).to.exist;
60+
// flip assertion after NODE-6047 implementation
61+
expect(commandStartedEvents[0]?.command?.readConcern).to.exist;
62+
expect(commandStartedEvents[0]?.command?.writeConcern).to.not.exist;
63+
});
64+
}
65+
});
66+
});
67+
});
68+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
{
2+
"description": "search index operations ignore read and write concern",
3+
"schemaVersion": "1.4",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0",
8+
"useMultipleMongoses": false,
9+
"uriOptions": {
10+
"readConcernLevel": "local",
11+
"w": 1
12+
},
13+
"observeEvents": [
14+
"commandStartedEvent"
15+
]
16+
}
17+
},
18+
{
19+
"database": {
20+
"id": "database0",
21+
"client": "client0",
22+
"databaseName": "database0"
23+
}
24+
},
25+
{
26+
"collection": {
27+
"id": "collection0",
28+
"database": "database0",
29+
"collectionName": "collection0"
30+
}
31+
}
32+
],
33+
"runOnRequirements": [
34+
{
35+
"minServerVersion": "7.0.0",
36+
"topologies": [
37+
"replicaset",
38+
"load-balanced",
39+
"sharded"
40+
],
41+
"serverless": "forbid"
42+
}
43+
],
44+
"tests": [
45+
{
46+
"description": "createSearchIndex ignores read and write concern",
47+
"operations": [
48+
{
49+
"name": "createSearchIndex",
50+
"object": "collection0",
51+
"arguments": {
52+
"model": {
53+
"definition": {
54+
"mappings": {
55+
"dynamic": true
56+
}
57+
}
58+
}
59+
},
60+
"expectError": {
61+
"isError": true,
62+
"errorContains": "Atlas"
63+
}
64+
}
65+
],
66+
"expectEvents": [
67+
{
68+
"client": "client0",
69+
"events": [
70+
{
71+
"commandStartedEvent": {
72+
"command": {
73+
"createSearchIndexes": "collection0",
74+
"indexes": [
75+
{
76+
"definition": {
77+
"mappings": {
78+
"dynamic": true
79+
}
80+
}
81+
}
82+
],
83+
"$db": "database0",
84+
"writeConcern": {
85+
"$$exists": false
86+
},
87+
"readConcern": {
88+
"$$exists": false
89+
}
90+
}
91+
}
92+
}
93+
]
94+
}
95+
]
96+
},
97+
{
98+
"description": "createSearchIndexes ignores read and write concern",
99+
"operations": [
100+
{
101+
"name": "createSearchIndexes",
102+
"object": "collection0",
103+
"arguments": {
104+
"models": []
105+
},
106+
"expectError": {
107+
"isError": true,
108+
"errorContains": "Atlas"
109+
}
110+
}
111+
],
112+
"expectEvents": [
113+
{
114+
"client": "client0",
115+
"events": [
116+
{
117+
"commandStartedEvent": {
118+
"command": {
119+
"createSearchIndexes": "collection0",
120+
"indexes": [],
121+
"$db": "database0",
122+
"writeConcern": {
123+
"$$exists": false
124+
},
125+
"readConcern": {
126+
"$$exists": false
127+
}
128+
}
129+
}
130+
}
131+
]
132+
}
133+
]
134+
},
135+
{
136+
"description": "dropSearchIndex ignores read and write concern",
137+
"operations": [
138+
{
139+
"name": "dropSearchIndex",
140+
"object": "collection0",
141+
"arguments": {
142+
"name": "test index"
143+
},
144+
"expectError": {
145+
"isError": true,
146+
"errorContains": "Atlas"
147+
}
148+
}
149+
],
150+
"expectEvents": [
151+
{
152+
"client": "client0",
153+
"events": [
154+
{
155+
"commandStartedEvent": {
156+
"command": {
157+
"dropSearchIndex": "collection0",
158+
"name": "test index",
159+
"$db": "database0",
160+
"writeConcern": {
161+
"$$exists": false
162+
},
163+
"readConcern": {
164+
"$$exists": false
165+
}
166+
}
167+
}
168+
}
169+
]
170+
}
171+
]
172+
},
173+
{
174+
"description": "listSearchIndexes ignores read and write concern",
175+
"operations": [
176+
{
177+
"name": "listSearchIndexes",
178+
"object": "collection0",
179+
"expectError": {
180+
"isError": true,
181+
"errorContains": "Atlas"
182+
}
183+
}
184+
],
185+
"expectEvents": [
186+
{
187+
"client": "client0",
188+
"events": [
189+
{
190+
"commandStartedEvent": {
191+
"command": {
192+
"aggregate": "collection0",
193+
"pipeline": [
194+
{
195+
"$listSearchIndexes": {}
196+
}
197+
],
198+
"writeConcern": {
199+
"$$exists": false
200+
},
201+
"readConcern": {
202+
"$$exists": false
203+
}
204+
}
205+
}
206+
}
207+
]
208+
}
209+
]
210+
},
211+
{
212+
"description": "updateSearchIndex ignores the read and write concern",
213+
"operations": [
214+
{
215+
"name": "updateSearchIndex",
216+
"object": "collection0",
217+
"arguments": {
218+
"name": "test index",
219+
"definition": {}
220+
},
221+
"expectError": {
222+
"isError": true,
223+
"errorContains": "Atlas"
224+
}
225+
}
226+
],
227+
"expectEvents": [
228+
{
229+
"client": "client0",
230+
"events": [
231+
{
232+
"commandStartedEvent": {
233+
"command": {
234+
"updateSearchIndex": "collection0",
235+
"name": "test index",
236+
"definition": {},
237+
"$db": "database0",
238+
"writeConcern": {
239+
"$$exists": false
240+
},
241+
"readConcern": {
242+
"$$exists": false
243+
}
244+
}
245+
}
246+
}
247+
]
248+
}
249+
]
250+
}
251+
]
252+
}

0 commit comments

Comments
 (0)