From dfd5a7c6984064a94937e952ee37b5e729093fee Mon Sep 17 00:00:00 2001 From: victor-meng <56978073+victor-meng@users.noreply.github.com> Date: Fri, 20 May 2022 16:39:21 -0700 Subject: [PATCH] Use undefined as the partition key value when deleting and updating documents (#1274) --- src/Common/dataAccess/deleteDocument.ts | 6 +++--- src/Common/dataAccess/updateDocument.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Common/dataAccess/deleteDocument.ts b/src/Common/dataAccess/deleteDocument.ts index 0ab2e6999..51713e791 100644 --- a/src/Common/dataAccess/deleteDocument.ts +++ b/src/Common/dataAccess/deleteDocument.ts @@ -1,9 +1,9 @@ import { CollectionBase } from "../../Contracts/ViewModels"; +import DocumentId from "../../Explorer/Tree/DocumentId"; +import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; import { client } from "../CosmosClient"; import { getEntityName } from "../DocumentUtility"; import { handleError } from "../ErrorHandlingUtils"; -import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import DocumentId from "../../Explorer/Tree/DocumentId"; export const deleteDocument = async (collection: CollectionBase, documentId: DocumentId): Promise => { const entityName: string = getEntityName(); @@ -13,7 +13,7 @@ export const deleteDocument = async (collection: CollectionBase, documentId: Doc await client() .database(collection.databaseId) .container(collection.id()) - .item(documentId.id(), documentId.partitionKeyValue) + .item(documentId.id(), documentId.partitionKeyValue?.length === 0 ? undefined : documentId.partitionKeyValue) .delete(); logConsoleInfo(`Successfully deleted ${entityName} ${documentId.id()}`); } catch (error) { diff --git a/src/Common/dataAccess/updateDocument.ts b/src/Common/dataAccess/updateDocument.ts index 7cda6566d..8aa100bbc 100644 --- a/src/Common/dataAccess/updateDocument.ts +++ b/src/Common/dataAccess/updateDocument.ts @@ -25,7 +25,7 @@ export const updateDocument = async ( const response = await client() .database(collection.databaseId) .container(collection.id()) - .item(documentId.id(), documentId.partitionKeyValue) + .item(documentId.id(), documentId.partitionKeyValue?.length === 0 ? undefined : documentId.partitionKeyValue) .replace(newDocument, options); logConsoleInfo(`Successfully updated ${entityName} ${documentId.id()}`);