diff --git a/less/Common/Constants.less b/less/Common/Constants.less index 4599cf6d7..214f1a0eb 100644 --- a/less/Common/Constants.less +++ b/less/Common/Constants.less @@ -104,6 +104,7 @@ @newCollectionPaneInputWidth: 300px; @tooltipTextWidth: 280px; @sharedCollectionThroughputTooltipTextWidth: 150px; +@mongoWildcardIndexTooltipWidth: 150px; @addContainerPaneThroughputInfoWidth: 370px; @optionsInfoWidth: 210px; @noFixedCollectionsTooltipWidth: 196px; diff --git a/less/documentDB.less b/less/documentDB.less index 45f14f69e..608e22566 100644 --- a/less/documentDB.less +++ b/less/documentDB.less @@ -1565,6 +1565,10 @@ p { min-width: @tooltipTextWidth; } +.mongoWildcardIndexTooltipWidth { + min-width: @mongoWildcardIndexTooltipWidth; +} + .sharedCollectionThroughputTooltipWidth { min-width: @sharedCollectionThroughputTooltipTextWidth; } diff --git a/src/Common/dataAccess/createCollection.ts b/src/Common/dataAccess/createCollection.ts index 204caba25..413481c90 100644 --- a/src/Common/dataAccess/createCollection.ts +++ b/src/Common/dataAccess/createCollection.ts @@ -29,6 +29,8 @@ import { refreshCachedResources } from "../DataAccessUtilityBase"; import { sendNotificationForError } from "./sendNotificationForError"; import { userContext } from "../../UserContext"; import { createDatabase } from "./createDatabase"; +import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; +import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants"; export const createCollection = async (params: DataModels.CreateCollectionParams): Promise => { let collection: DataModels.Collection; @@ -138,6 +140,7 @@ const createSqlContainer = async (params: DataModels.CreateCollectionParams): Pr }; const createMongoCollection = async (params: DataModels.CreateCollectionParams): Promise => { + const mongoWildcardIndexOnAllFields: ARMTypes.MongoIndex[] = [{ key: { keys: ["$**"] } }, { key: { keys: ["_id"] } }]; try { const getResponse = await getMongoDBCollection( userContext.subscriptionId, @@ -166,6 +169,9 @@ const createMongoCollection = async (params: DataModels.CreateCollectionParams): const partitionKeyPath: string = params.partitionKey.paths[0]; resource.shardKey = { [partitionKeyPath]: "Hash" }; } + if (params.createMongoWildcardIndex) { + resource.indexes = mongoWildcardIndexOnAllFields; + } const rpPayload: ARMTypes.MongoDBCollectionCreateUpdateParameters = { properties: { @@ -182,6 +188,13 @@ const createMongoCollection = async (params: DataModels.CreateCollectionParams): params.collectionId, rpPayload ); + + if (params.createMongoWildcardIndex) { + TelemetryProcessor.trace(Action.CreateMongoCollectionWithWildcardIndex, ActionModifiers.Mark, { + message: "Mongo Collection created with wildcard index on all fields." + }); + } + return createResponse && (createResponse.properties.resource as DataModels.Collection); }; diff --git a/src/Contracts/DataModels.ts b/src/Contracts/DataModels.ts index 067c5e2f8..3c1b8474a 100644 --- a/src/Contracts/DataModels.ts +++ b/src/Contracts/DataModels.ts @@ -287,6 +287,7 @@ export interface CreateCollectionParams { indexingPolicy?: IndexingPolicy; partitionKey?: PartitionKey; uniqueKeyPolicy?: UniqueKeyPolicy; + createMongoWildcardIndex?: boolean; } export interface ReadDatabaseOfferParams { diff --git a/src/Explorer/Explorer.ts b/src/Explorer/Explorer.ts index 07bc6e44d..be40ea8f2 100644 --- a/src/Explorer/Explorer.ts +++ b/src/Explorer/Explorer.ts @@ -133,6 +133,7 @@ export default class Explorer { public isPreferredApiGraph: ko.Computed; public isPreferredApiTable: ko.Computed; public isFixedCollectionWithSharedThroughputSupported: ko.Computed; + public isEnableMongoCapabilityPresent: ko.Computed; public isServerlessEnabled: ko.Computed; public isEmulator: boolean; public isAccountReady: ko.Observable; @@ -522,22 +523,7 @@ export default class Explorer { return false; } - const capabilities = this.databaseAccount().properties && this.databaseAccount().properties.capabilities; - - if (!capabilities) { - return false; - } - - for (let i = 0; i < capabilities.length; i++) { - if (typeof capabilities[i] === "object") { - if (capabilities[i].name === Constants.CapabilityNames.EnableMongo) { - // version 3.6 - return true; - } - } - } - - return false; + return this.isEnableMongoCapabilityPresent(); }); this.isServerlessEnabled = ko.computed( @@ -569,6 +555,21 @@ export default class Explorer { return false; }); + this.isEnableMongoCapabilityPresent = ko.computed(() => { + const capabilities = this.databaseAccount && this.databaseAccount()?.properties?.capabilities; + if (!capabilities) { + return false; + } + + for (let i = 0; i < capabilities.length; i++) { + if (typeof capabilities[i] === "object" && capabilities[i].name === Constants.CapabilityNames.EnableMongo) { + return true; + } + } + + return false; + }); + this.isHostedDataExplorerEnabled = ko.computed( () => this.getPlatformType() === PlatformType.Portal && diff --git a/src/Explorer/Panes/AddCollectionPane.html b/src/Explorer/Panes/AddCollectionPane.html index 346633c36..94d704046 100644 --- a/src/Explorer/Panes/AddCollectionPane.html +++ b/src/Explorer/Panes/AddCollectionPane.html @@ -418,7 +418,6 @@ -
@@ -511,6 +510,23 @@ + +
+

+ Indexing +

+ + Create a Wildcard Index on all fields + + More information + + By default, only the field _id is indexed. Creating a wildcard index on all fields will quickly optimize query performance and is recommended during development. + + +
+ +
diff --git a/src/Explorer/Panes/AddCollectionPane.ts b/src/Explorer/Panes/AddCollectionPane.ts index 61a21bc36..be4520912 100644 --- a/src/Explorer/Panes/AddCollectionPane.ts +++ b/src/Explorer/Panes/AddCollectionPane.ts @@ -99,6 +99,7 @@ export default class AddCollectionPane extends ContextualPaneBase { public ruToolTipText: ko.Computed; public canConfigureThroughput: ko.PureComputed; public showUpsellMessage: ko.PureComputed; + public shouldCreateMongoWildcardIndex: ko.Observable; private _databaseOffers: HashMap; private _isSynapseLinkEnabled: ko.Computed; @@ -660,6 +661,8 @@ export default class AddCollectionPane extends ContextualPaneBase { changedSelectedValueTo: value ? ActionModifiers.IndexAll : ActionModifiers.NoIndex }); }); + + this.shouldCreateMongoWildcardIndex = ko.observable(false); } public getSharedThroughputDefault(): boolean { @@ -832,9 +835,10 @@ export default class AddCollectionPane extends ContextualPaneBase { let collectionId: string = this.collectionId().trim(); let indexingPolicy: DataModels.IndexingPolicy; + let createMongoWildcardIndex: boolean; // todo - remove mongo indexing policy ticket # 616274 if (this.container.isPreferredApiMongoDB()) { - indexingPolicy = SharedConstants.IndexingPolicies.Mongo; + createMongoWildcardIndex = this.shouldCreateMongoWildcardIndex(); } else if (this.showIndexingOptionsForSharedThroughput()) { if (this.useIndexingForSharedThroughput()) { indexingPolicy = SharedConstants.IndexingPolicies.AllPropertiesIndexed; @@ -864,7 +868,8 @@ export default class AddCollectionPane extends ContextualPaneBase { autoPilotMaxThroughput, indexingPolicy, partitionKey, - uniqueKeyPolicy + uniqueKeyPolicy, + createMongoWildcardIndex }; createCollection(createCollectionParams).then( diff --git a/src/Shared/Constants.ts b/src/Shared/Constants.ts index 213877d10..9cf5cb402 100644 --- a/src/Shared/Constants.ts +++ b/src/Shared/Constants.ts @@ -228,42 +228,6 @@ export class IndexingPolicies { ], excludedPaths: [] }; - - // todo - remove mongo indexing policy ticket # 616274 - public static Mongo = { - indexingMode: "consistent", - automatic: true, - includedPaths: [ - { - path: "/*", - indexes: [ - { - kind: "Range", - dataType: "Number", - precision: -1 - }, - { - kind: "Range", - dataType: "String", - precision: -1 - }, - { - kind: "Spatial", - dataType: "Point" - }, - { - kind: "Spatial", - dataType: "LineString" - }, - { - kind: "Spatial", - dataType: "Polygon" - } - ] - } - ], - excludedPaths: [] - }; } export class SubscriptionUtilMappings { diff --git a/src/Shared/Telemetry/TelemetryConstants.ts b/src/Shared/Telemetry/TelemetryConstants.ts index 97a4c303f..8bfc0b943 100644 --- a/src/Shared/Telemetry/TelemetryConstants.ts +++ b/src/Shared/Telemetry/TelemetryConstants.ts @@ -71,7 +71,8 @@ export enum Action { NotebooksGitHubManageRepo, NotebooksGitHubCommit, NotebooksGitHubDisconnect, - OpenTerminal + OpenTerminal, + CreateMongoCollectionWithWildcardIndex } export const ActionModifiers = {