From 2f4184d080e3f4822e0e37c8730452edb5a605c1 Mon Sep 17 00:00:00 2001 From: David Jimenez Barrantes Date: Tue, 31 Oct 2023 11:27:32 -0600 Subject: [PATCH] Removes unnecessary ANDs --- .../src/repository/Db.ts | 10 +++------ .../src/repository/Update.ts | 21 +++++++------------ .../src/repository/Upsert.ts | 10 +++------ .../test/integration/Db.test.ts | 10 +++------ 4 files changed, 16 insertions(+), 35 deletions(-) diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Db.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Db.ts index 605029e2..b2f2df5c 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Db.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Db.ts @@ -143,13 +143,9 @@ export async function lockDocuments( await concurrencyCollection.deleteMany( { - $and: [ - { - _id: { - $in: documentUuids, - }, - }, - ], + _id: { + $in: documentUuids, + }, }, { session }, ); diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Update.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Update.ts index 46e5a7be..bb3ac95d 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Update.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Update.ts @@ -154,14 +154,11 @@ async function updateAllowingIdentityChange( const referringDocumentUuids: WithId[] = await mongoCollection .find( { - $and: [ - { - aliasMeadowlarkIds: { - $in: document.outboundRefs, - }, - }, - ], + aliasMeadowlarkIds: { + $in: document.outboundRefs, + }, }, + { projection: { documentUuid: 1 } }, ) .toArray(); @@ -265,13 +262,9 @@ async function updateDisallowingIdentityChange( const referringDocumentUuids: WithId[] = await mongoCollection .find( { - $and: [ - { - aliasMeadowlarkIds: { - $in: document.outboundRefs, - }, - }, - ], + aliasMeadowlarkIds: { + $in: document.outboundRefs, + }, }, { projection: { documentUuid: 1 } }, ) diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Upsert.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Upsert.ts index 84d05181..4023a4e6 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Upsert.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/src/repository/Upsert.ts @@ -141,13 +141,9 @@ export async function upsertDocumentTransaction( const referringDocumentUuids: WithId[] = await mongoCollection .find( { - $and: [ - { - aliasMeadowlarkIds: { - $in: document.outboundRefs, - }, - }, - ], + aliasMeadowlarkIds: { + $in: document.outboundRefs, + }, }, { projection: { documentUuid: 1 } }, ) diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Db.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Db.test.ts index 05c17c46..f50c17fc 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Db.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Db.test.ts @@ -32,13 +32,9 @@ describe('when lockDocuments is called with a given number of documents', () => it('concurrencyCollection should be empty after the function is called', async () => { const documents = await getConcurrencyCollection(client).countDocuments({ - $and: [ - { - meadowlarkId: { - $in: ['123', '456'], - }, - }, - ], + meadowlarkId: { + $in: ['123', '456'], + }, }); expect(documents).toBe(0);