-
Type: Bug
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: Bulk API
What problem are you facing?
`Collection.bulkWrite` and `Collection.initialize*BulkOp().execute()` do not respect the user provided pkFactory when generating document ids.
This can lead to inconsistent data if regular crud APIs are used as well as bulk APIs.
This notably does not apply to Collection.insertMany().
What driver and relevant dependency versions are you using?
latest, but the behavior has been here forever.
Steps to reproduce?
import { randomBytes } from 'crypto'; import { MongoClient } from './src/mongo_client'; async function main() { const client = await MongoClient.connect(process.env.MONGODB_URI!, { pkFactory: { count: 0, createPk: function () { return this.count++; } } }); const collection = client.db('foo').collection(randomBytes(8).toString('utf-8')); await collection.insertMany([{ a: 1 }, { a: 2 }, { a: 3 }]); await collection.bulkWrite([{ insertOne: { a: 1 } }]); console.log(await collection.find().toArray()); } main(); // output: // [ // { _id: 0, a: 1 }, // { _id: 1, a: 2 }, // { _id: 2, a: 3 }, // { _id: new ObjectId("65036cbf71bcb5518605c620"), a: 1 } // ]
- is duplicated by
-
NODE-5637 bulk write APIs do not use pkFactory when creating document _ids
- Closed