Skip to content

Commit 332b8b8

Browse files
committed
Do not pass writeOptions in database calls.
- Fix `findOneAndUpdate` options.
1 parent 66aba99 commit 332b8b8

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# bedrock-tokenization ChangeLog
22

3+
## 22.1.2 - 2025-mm-dd
4+
5+
### Fixed
6+
- Do not pass `writeOptions` in database calls.
7+
- Use proper `"returnDocument": "after"` option w/`findOneAndUpdate`.
8+
39
## 22.1.1 - 2025-03-04
410

511
### Fixed

lib/batchVersions.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ export async function setOptions({options, explain = false} = {}) {
236236
};
237237
const query = {'batchVersionOptions.id': BATCH_OPTIONS_ID};
238238
const $set = {batchVersionOptions, 'meta.updated': now};
239-
const upsertOptions = {...database.writeOptions, upsert: true};
240239

241240
if(explain) {
242241
// 'find().limit(1)' is used here because 'updateOne()' doesn't return a
@@ -248,7 +247,7 @@ export async function setOptions({options, explain = false} = {}) {
248247
const result = await collection.updateOne(query, {
249248
$set,
250249
$setOnInsert: {'meta.created': now}
251-
}, upsertOptions);
250+
}, {upsert: true});
252251
if(result.modifiedCount > 0 || result.upsertedCount > 0) {
253252
// upserted or modified
254253
return true;

lib/documents.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,9 +636,8 @@ export async function _refresh({
636636
const result = await collection.findOneAndUpdate(
637637
query, update, {
638638
projection,
639-
returnNewDocument: true,
640-
promoteBuffers: true,
641-
...database.writeOptions
639+
returnDocument: 'after',
640+
promoteBuffers: true
642641
});
643642
// return whether update occurred and new record if it did
644643
return {updated: result.lastErrorObject.n !== 0, record: result.value};

lib/entities.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ export async function _upsert({
463463
$setOnInsert['entity.externalIdHash'] = externalIdHash;
464464
}
465465
const record = {entity, meta};
466-
const upsertOptions = {...database.writeOptions, upsert: true};
467466

468467
if(explain) {
469468
// 'find().limit(1)' is used here because 'updateOne()' doesn't return a
@@ -473,7 +472,7 @@ export async function _upsert({
473472
}
474473

475474
// this upsert cannot trigger duplicate error; no try/catch needed
476-
const result = await collection.updateOne(query, update, upsertOptions);
475+
const result = await collection.updateOne(query, update, {upsert: true});
477476
if(result.upsertedCount > 0) {
478477
// return full record when upserted
479478
return {_id: result.upsertedId, ...record};

0 commit comments

Comments
 (0)