Skip to content

Commit

Permalink
fix: read preference after create & update
Browse files Browse the repository at this point in the history
  • Loading branch information
7sete7 committed Mar 6, 2025
1 parent 7ad5079 commit c1539ba
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/imports/data/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ export async function create({ authTokenId, document, data, contextUser, upsert,
return errorReturn(`[${document}] Error on insert, there is no affected record`);
}

const affectedRecord = await collection.findOne(insertedQuery, { session: dbSession });
const affectedRecord = await collection.findOne(insertedQuery, { session: dbSession, readPreference: "primary" });
const resultRecord = removeUnauthorizedDataForRead(access, affectedRecord, user, metaObject);

if (isEmpty(MetaObject.Namespace.onCreate) === false) {
Expand Down Expand Up @@ -1401,7 +1401,7 @@ export async function update({ authTokenId, document, data, contextUser, tracing
merge(updatedQuery, readFilter);
}

const updatedRecords = await collection.find(updatedQuery, { session: dbSession }).toArray();
const updatedRecords = await collection.find(updatedQuery, { session: dbSession, readPreference: "primary" }).toArray();

if (metaObject.scriptAfterSave != null) {
tracingSpan?.addEvent('Running scriptAfterSave');
Expand Down

0 comments on commit c1539ba

Please sign in to comment.