Skip to content

Commit

Permalink
feat(shell-api): warn users when using background option in aggregate M…
Browse files Browse the repository at this point in the history
…ONGOSH-1766 (#1964)

* warn users when using background option in aggregate

* text change
  • Loading branch information
mabaasit authored May 2, 2024
1 parent 6d9162c commit 16cbc95
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/shell-api/src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
coerceToJSNumber,
buildConfigChunksCollectionMatch,
onlyShardedCollectionsInConfigFilter,
aggregateBackgroundOptionNotSupportedHelp,
} from './helpers';
import type {
AnyBulkWriteOperation,
Expand Down Expand Up @@ -177,6 +178,11 @@ export default class Collection extends ShellApiWithMongoClass {
options = {};
pipeline = args || [];
}
if ('background' in options) {
this._instanceState.printWarning(
aggregateBackgroundOptionNotSupportedHelp
);
}
this._emitCollectionApiCall('aggregate', { options, pipeline });
const { aggOptions, dbOptions, explain } = adaptAggregateOptions(options);

Expand Down
6 changes: 6 additions & 0 deletions packages/shell-api/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
shouldRunAggregationImmediately,
adjustRunCommand,
getBadge,
aggregateBackgroundOptionNotSupportedHelp,
} from './helpers';

import {
Expand Down Expand Up @@ -421,6 +422,11 @@ export default class Database extends ShellApiWithMongoClass {
pipeline: Document[],
options?: Document
): Promise<AggregationCursor> {
if ('background' in (options ?? {})) {
this._instanceState.printWarning(
aggregateBackgroundOptionNotSupportedHelp
);
}
assertArgsDefinedType([pipeline], [true], 'Database.aggregate');
this._emitDatabaseApiCall('aggregate', { options, pipeline });

Expand Down
4 changes: 4 additions & 0 deletions packages/shell-api/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1187,3 +1187,7 @@ export function buildConfigChunksCollectionMatch(
? { uuid: configCollectionsInfo.uuid } // new format
: { ns: configCollectionsInfo._id }; // old format
}

export const aggregateBackgroundOptionNotSupportedHelp =
'the background option is not supported by the aggregate method and will be ignored, ' +
'use runCommand to use { background: true } with Atlas Data Federation';

0 comments on commit 16cbc95

Please sign in to comment.