Skip to content

Remove write options #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# bedrock-tokenization ChangeLog

## 22.1.2 - 2025-mm-dd

### Fixed
- Do not pass `writeOptions` in database calls.
- Use proper `"returnDocument": "after"` option w/`findOneAndUpdate`.
- Pass `includeResultMetadata: true` to `findOneAndUpdate` to ensure meta data
is always returned.

## 22.1.1 - 2025-03-04

### Fixed
Expand Down
3 changes: 1 addition & 2 deletions lib/batchVersions.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ export async function setOptions({options, explain = false} = {}) {
};
const query = {'batchVersionOptions.id': BATCH_OPTIONS_ID};
const $set = {batchVersionOptions, 'meta.updated': now};
const upsertOptions = {...database.writeOptions, upsert: true};

if(explain) {
// 'find().limit(1)' is used here because 'updateOne()' doesn't return a
Expand All @@ -248,7 +247,7 @@ export async function setOptions({options, explain = false} = {}) {
const result = await collection.updateOne(query, {
$set,
$setOnInsert: {'meta.created': now}
}, upsertOptions);
}, {upsert: true});
if(result.modifiedCount > 0 || result.upsertedCount > 0) {
// upserted or modified
return true;
Expand Down
4 changes: 2 additions & 2 deletions lib/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,9 @@ export async function _refresh({
const result = await collection.findOneAndUpdate(
query, update, {
projection,
returnNewDocument: true,
returnDocument: 'after',
promoteBuffers: true,
...database.writeOptions
includeResultMetadata: true
});
// return whether update occurred and new record if it did
return {updated: result.lastErrorObject.n !== 0, record: result.value};
Expand Down
3 changes: 1 addition & 2 deletions lib/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ export async function _upsert({
$setOnInsert['entity.externalIdHash'] = externalIdHash;
}
const record = {entity, meta};
const upsertOptions = {...database.writeOptions, upsert: true};

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

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