Skip to content

Commit 298f6eb

Browse files
committed
fix: collation issue with index creation
1 parent 886a661 commit 298f6eb

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/operations/indexes.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { indexInformation, IndexInformationOptions } from './common_functions';
22
import { OperationBase, Aspect, defineAspects } from './operation';
33
import { MongoError } from '../error';
4-
import { maxWireVersion, parseIndexOptions, MongoDBNamespace, Callback } from '../utils';
4+
import {
5+
maxWireVersion,
6+
parseIndexOptions,
7+
MongoDBNamespace,
8+
Callback,
9+
deepFreeze
10+
} from '../utils';
511
import { CommandOperation, CommandOperationOptions, OperationParent } from './command';
612
import { ReadPreference } from '../read_preference';
713
import type { Server } from '../sdam/server';
@@ -141,6 +147,14 @@ export class CreateIndexesOperation extends CommandOperation<CreateIndexesOption
141147
onlyReturnNameOfCreatedIndex?: boolean;
142148
indexes: IndexDescription[];
143149

150+
get builtOptions(): Readonly<CreateIndexesOptions> {
151+
return deepFreeze({
152+
...super.builtOptions,
153+
// collation is set on each index, it should not be defined at the root
154+
collation: undefined
155+
});
156+
}
157+
144158
constructor(
145159
parent: OperationParent,
146160
collectionName: string,
@@ -157,7 +171,7 @@ export class CreateIndexesOperation extends CommandOperation<CreateIndexesOption
157171
}
158172

159173
execute(server: Server, callback: Callback<Document>): void {
160-
const options = this.options;
174+
const options = this.builtOptions;
161175
const indexes = this.indexes;
162176

163177
const serverWireVersion = maxWireVersion(server);
@@ -199,9 +213,6 @@ export class CreateIndexesOperation extends CommandOperation<CreateIndexesOption
199213
cmd.commitQuorum = options.commitQuorum;
200214
}
201215

202-
// collation is set on each index, it should not be defined at the root
203-
this.options.collation = undefined;
204-
205216
super.executeCommand(server, cmd, (err, result) => {
206217
if (err) {
207218
callback(err);

0 commit comments

Comments
 (0)