From 16cbc95001082ca44e50117c3af3e59ffd7eab89 Mon Sep 17 00:00:00 2001 From: Basit <1305718+mabaasit@users.noreply.github.com> Date: Thu, 2 May 2024 09:05:38 +0200 Subject: [PATCH] feat(shell-api): warn users when using background option in aggregate MONGOSH-1766 (#1964) * warn users when using background option in aggregate * text change --- packages/shell-api/src/collection.ts | 6 ++++++ packages/shell-api/src/database.ts | 6 ++++++ packages/shell-api/src/helpers.ts | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/packages/shell-api/src/collection.ts b/packages/shell-api/src/collection.ts index e73664d79..ec6c533fd 100644 --- a/packages/shell-api/src/collection.ts +++ b/packages/shell-api/src/collection.ts @@ -41,6 +41,7 @@ import { coerceToJSNumber, buildConfigChunksCollectionMatch, onlyShardedCollectionsInConfigFilter, + aggregateBackgroundOptionNotSupportedHelp, } from './helpers'; import type { AnyBulkWriteOperation, @@ -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); diff --git a/packages/shell-api/src/database.ts b/packages/shell-api/src/database.ts index 842cb4628..86ae4340f 100644 --- a/packages/shell-api/src/database.ts +++ b/packages/shell-api/src/database.ts @@ -24,6 +24,7 @@ import { shouldRunAggregationImmediately, adjustRunCommand, getBadge, + aggregateBackgroundOptionNotSupportedHelp, } from './helpers'; import { @@ -421,6 +422,11 @@ export default class Database extends ShellApiWithMongoClass { pipeline: Document[], options?: Document ): Promise { + if ('background' in (options ?? {})) { + this._instanceState.printWarning( + aggregateBackgroundOptionNotSupportedHelp + ); + } assertArgsDefinedType([pipeline], [true], 'Database.aggregate'); this._emitDatabaseApiCall('aggregate', { options, pipeline }); diff --git a/packages/shell-api/src/helpers.ts b/packages/shell-api/src/helpers.ts index 06d2253d9..85bd1d453 100644 --- a/packages/shell-api/src/helpers.ts +++ b/packages/shell-api/src/helpers.ts @@ -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';