-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(NODE-6329): client bulk write happy path
- Loading branch information
Showing
19 changed files
with
2,180 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { Server } from '../../sdam/server'; | ||
import type { ClientSession } from '../../sessions'; | ||
import { AbstractOperation, Aspect, defineAspects } from '../operation'; | ||
import { ClientBulkWriteCommandBuilder } from './command_builder'; | ||
import { | ||
type AnyClientBulkWriteModel, | ||
type ClientBulkWriteOptions, | ||
type ClientBulkWriteResult | ||
} from './common'; | ||
import { ClientBulkWriteResultsMerger } from './results_merger'; | ||
|
||
export class ClientBulkWriteOperation extends AbstractOperation<ClientBulkWriteResult> { | ||
override options: ClientBulkWriteOptions; | ||
operations: AnyClientBulkWriteModel[]; | ||
|
||
override get commandName() { | ||
return 'bulkWrite' as const; | ||
} | ||
|
||
constructor(operations: AnyClientBulkWriteModel[], options: ClientBulkWriteOptions) { | ||
super(options); | ||
this.options = options; | ||
this.operations = operations; | ||
} | ||
|
||
override async execute( | ||
server: Server, | ||
session: ClientSession | undefined | ||
): Promise<ClientBulkWriteResult> { | ||
const options = { ...this.options, ...this.bsonOptions, readPreference: this.readPreference }; | ||
|
||
const commmandBuilder = new ClientBulkWriteCommandBuilder(this.operations, options); | ||
const commands = commmandBuilder.buildCommands(); | ||
const resultsMerger = new ClientBulkWriteResultsMerger(options); | ||
for (const command of commands) { | ||
const cursor = new ClientBulkWriteCursor(command, options); | ||
for await (const docs of cursor.toArray()) { | ||
resultsMerger.merge(docs); | ||
} | ||
} | ||
return resultsMerger.result; | ||
} | ||
} | ||
|
||
defineAspects(ClientBulkWriteOperation, [Aspect.WRITE_OPERATION]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Document } from '../../bson'; | ||
import { ClientBulkWriteOptions, ClientBulkWriteResult } from './common'; | ||
|
||
export class ClientBulkWriteResultsMerger { | ||
result: ClientBulkWriteResult; | ||
options: ClientBulkWriteOptions; | ||
|
||
constructor(options: ClientBulkWriteOptions) { | ||
this.options = options; | ||
this.result = { | ||
insertedCount: 0, | ||
upsertedCount: 0, | ||
matchedCount: 0, | ||
modifiedCount: 0, | ||
deletedCount: 0 | ||
}; | ||
} | ||
|
||
merge(documents: Document[]): ClientBulkWriteResultsMerger { | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.