Skip to content
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

fix(NODE-5636): generate _ids using pkFactory in bulk write operations #4025

Conversation

baileympearson
Copy link
Contributor

@baileympearson baileympearson commented Mar 6, 2024

Description

What is changing?

Bulk operations now generate _ids for inserted documents using the pkFactory, if the user has provided one.

Is there new documentation needed for these changes?

No.

What is the motivation for this change?

Release Highlight

Bulk Write Operations Generate Ids using pkFactory

When performing inserts, the driver automatically generates _ids for each document if there is no _id present. By default, the driver generates ObjectIds. An option, pkFactory, can be used to configure the driver to generate _ids that are not object ids.

For a long time, only Collection.insert and Collection.insertMany actually used the pkFactory, if configured. Notably, Collection.bulkWrite(), Collection.initializeOrderedBulkOp() and Collection.initializeOrderedBulkOp() always generated ObjectIds, regardless of what was configured on collection.

The driver always generates _ids for inserted documents using the pkFactory.

Caution

If you are using a pkFactory and performing bulk writes, you may have inserted data into your database that does not have _ids generated by the pkFactory.

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@baileympearson baileympearson force-pushed the fix-pkfactory-generation-in-bulk-operations branch from 65caa5a to eded423 Compare March 7, 2024 18:02
@baileympearson baileympearson changed the title fix(NODE-xxxx): generate _ids using pkFactory in bulk write operations fix(NODE-5636): generate _ids using pkFactory in bulk write operations Mar 7, 2024
@baileympearson baileympearson marked this pull request as ready for review March 7, 2024 18:14
@nbbeeken nbbeeken self-assigned this Mar 8, 2024
@nbbeeken nbbeeken added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Mar 8, 2024
Copy link
Contributor

@nbbeeken nbbeeken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, a few tiny cleanups

src/bulk/common.ts Outdated Show resolved Hide resolved
src/operations/insert.ts Outdated Show resolved Hide resolved
test/integration/crud/bulk.test.ts Outdated Show resolved Hide resolved
src/operations/common_functions.ts Show resolved Hide resolved
test/integration/crud/bulk.test.ts Show resolved Hide resolved
src/bulk/common.ts Outdated Show resolved Hide resolved
src/bulk/common.ts Outdated Show resolved Hide resolved
@nbbeeken nbbeeken merged commit fbb5059 into mongodb:main Mar 8, 2024
16 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Primary Review In Review with primary reviewer, not yet ready for team's eyes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants