Skip to content

Commit 1676135

Browse files
authored
fix(@mongodb-js/compass-schema-validation): Pass full namespace to updateCollection instead of passing collMod option (#2426)
* fix(mongodb-data-service): Change merge order to restore pre-typescript method behavior * fix(@mongodb-js/compass-schema-validation, mongodb-data-service): Pass full namespace to the updateCommand; Add comments explaining why the order of args is important * chore(mongodb-data-service): One "explicitly" is more than enough * chore: More typo fixes
1 parent 81afb35 commit 1676135

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/compass-schema-validation/src/modules/validation.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,8 @@ export const saveValidation = (validation) => {
471471
'schema-validation-saved'
472472
);
473473
dataService.updateCollection(
474-
namespace.database,
474+
`${namespace.database}.${namespace.collection}`,
475475
{
476-
collMod: namespace.collection,
477476
validator: savedValidation.validator,
478477
validationAction: savedValidation.validationAction,
479478
validationLevel: savedValidation.validationLevel

packages/data-service/src/native-client.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,14 +1102,19 @@ class NativeClient extends EventEmitter {
11021102
*/
11031103
updateCollection(
11041104
ns: string,
1105-
flags: Document,
1105+
// Collection name to update that will be passed to the collMod command will
1106+
// be derived from the provided namespace, this is why we are explicitly
1107+
// prohibiting to pass collMod flag here
1108+
flags: Document & { collMod?: never },
11061109
callback: Callback<Document>
11071110
): void {
11081111
const collectionName = this._collectionName(ns);
11091112
const db = this.client.db(this._databaseName(ns));
1113+
// Order of arguments is important here, collMod is a command name and it
1114+
// should always be the first one in the object
11101115
const command = {
1111-
...flags,
11121116
collMod: collectionName,
1117+
...flags,
11131118
};
11141119
db.command(command, (error, result) => {
11151120
if (error) {

0 commit comments

Comments
 (0)