Skip to content

Commit

Permalink
feat(NODE-6329): client bulk write happy path
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Aug 29, 2024
1 parent 6d65ae7 commit 5c65c07
Show file tree
Hide file tree
Showing 15 changed files with 2,068 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/cursor/client_bulk_write_cursor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { AbstractCursor } from './abstract_cursor';

export class ClientBulkWriteCursor extends AbstractCursor {

Check failure on line 3 in src/cursor/client_bulk_write_cursor.ts

View workflow job for this annotation

GitHub Actions / build

Non-abstract class 'ClientBulkWriteCursor' is missing implementations for the following members of 'AbstractCursor<any, AbstractCursorEvents>': 'clone', '_initialize'.

}
4 changes: 4 additions & 0 deletions src/mongo_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
return this.s.bsonOptions;
}

async bulkWrite(): Promise<ClientBulkWriteResult> {

Check failure on line 478 in src/mongo_client.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'ClientBulkWriteResult'.

}

/**
* Connect to MongoDB using a url
*
Expand Down
77 changes: 77 additions & 0 deletions src/operations/client_bulk_write/client_bulk_write.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { AbstractOperation } from '../operation';

export interface ClientBulkWriteResult {
/**
* The total number of documents inserted across all insert operations.
*/
insertedCount: number;
/**
* The total number of documents upserted across all update operations.
*/
upsertedCount: number;
/**
* The total number of documents matched across all update operations.
*/
matchedCount: number;
/**
* The total number of documents modified across all update operations.
*/
modifiedCount: number;
/**
* The total number of documents deleted across all delete operations.
*/
deletedCount: number;
}

export interface VerboseClientBulkWriteResult extends ClientBulkWriteResult {
/**
* The results of each individual insert operation that was successfully performed.
*/
insertResults: Map<number, ClientInsertOneResult>;
/**
* The results of each individual update operation that was successfully performed.
*/
updateResults: Map<number, ClientUpdateResult>;
/**
* The results of each individual delete operation that was successfully performed.
*/
deleteResults: Map<number, ClientDeleteResult>;
}

export interface ClientInsertOneResult {
/**
* The _id of the inserted document.
*/
insertedId: any;
}

export interface ClientUpdateResult {
/**
* The number of documents that matched the filter.
*/
matchedCount: number;

/**
* The number of documents that were modified.
*/
modifiedCount: number;

/**
* The _id field of the upserted document if an upsert occurred.
*
* It MUST be possible to discern between a BSON Null upserted ID value and this field being
* unset. If necessary, drivers MAY add a didUpsert boolean field to differentiate between
* these two cases.
*/
upsertedId?: any;
}

export interface ClientDeleteResult {
/**
* The number of documents that were deleted.
*/
deletedCount: number;
}

export class ClientBulkWriteOperation extends AbstractOperation<ClientBulkWriteResult> {

Check failure on line 76 in src/operations/client_bulk_write/client_bulk_write.ts

View workflow job for this annotation

GitHub Actions / build

Non-abstract class 'ClientBulkWriteOperation' is missing implementations for the following members of 'AbstractOperation<ClientBulkWriteResult>': 'commandName', 'execute'.
}
5 changes: 1 addition & 4 deletions test/integration/crud/crud.spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';

const clientBulkWriteTests = new RegExp(
[
'client bulk write delete with collation',
'client bulk write delete with hint',
'client bulkWrite operations support errorResponse assertions',
'an individual operation fails during an ordered bulkWrite',
'an individual operation fails during an unordered bulkWrite',
'detailed results are omitted from error when verboseResults is false',
'a top-level failure occurs during a bulkWrite',
'a bulk write with only errors does not report a partial result',
'an empty list of write models is a client-side error',
'a write concern error occurs during a bulkWrite',
'client bulkWrite'
'a write concern error occurs during a bulkWrite'
].join('|')
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
{
"description": "unacknowledged-client-bulkWrite",
"schemaVersion": "1.7",
"runOnRequirements": [
{
"minServerVersion": "8.0"
}
],
"createEntities": [
{
"client": {
"id": "client",
"useMultipleMongoses": false,
"observeEvents": [
"commandStartedEvent",
"commandSucceededEvent",
"commandFailedEvent"
],
"uriOptions": {
"w": 0
}
}
},
{
"database": {
"id": "database",
"client": "client",
"databaseName": "command-monitoring-tests"
}
},
{
"collection": {
"id": "collection",
"database": "database",
"collectionName": "test"
}
}
],
"initialData": [
{
"collectionName": "test",
"databaseName": "command-monitoring-tests",
"documents": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
]
}
],
"_yamlAnchors": {
"namespace": "command-monitoring-tests.test"
},
"tests": [
{
"description": "A successful mixed client bulkWrite",
"operations": [
{
"object": "client",
"name": "clientBulkWrite",
"arguments": {
"models": [
{
"insertOne": {
"namespace": "command-monitoring-tests.test",
"document": {
"_id": 4,
"x": 44
}
}
},
{
"updateOne": {
"namespace": "command-monitoring-tests.test",
"filter": {
"_id": 3
},
"update": {
"$set": {
"x": 333
}
}
}
}
]
},
"expectResult": {
"insertedCount": {
"$$unsetOrMatches": 0
},
"upsertedCount": {
"$$unsetOrMatches": 0
},
"matchedCount": {
"$$unsetOrMatches": 0
},
"modifiedCount": {
"$$unsetOrMatches": 0
},
"deletedCount": {
"$$unsetOrMatches": 0
},
"insertResults": {
"$$unsetOrMatches": {}
},
"updateResults": {
"$$unsetOrMatches": {}
},
"deleteResults": {
"$$unsetOrMatches": {}
}
}
},
{
"object": "collection",
"name": "find",
"arguments": {
"filter": {}
},
"expectResult": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 333
},
{
"_id": 4,
"x": 44
}
]
}
],
"expectEvents": [
{
"client": "client",
"ignoreExtraEvents": true,
"events": [
{
"commandStartedEvent": {
"commandName": "bulkWrite",
"databaseName": "admin",
"command": {
"bulkWrite": 1,
"errorsOnly": true,
"ordered": true,
"ops": [
{
"insert": 0,
"document": {
"_id": 4,
"x": 44
}
},
{
"update": 0,
"filter": {
"_id": 3
},
"updateMods": {
"$set": {
"x": 333
}
},
"multi": false
}
],
"nsInfo": [
{
"ns": "command-monitoring-tests.test"
}
]
}
}
},
{
"commandSucceededEvent": {
"commandName": "bulkWrite",
"reply": {
"ok": 1,
"nInserted": {
"$$exists": false
},
"nMatched": {
"$$exists": false
},
"nModified": {
"$$exists": false
},
"nUpserted": {
"$$exists": false
},
"nDeleted": {
"$$exists": false
}
}
}
}
]
}
]
}
]
}
Loading

0 comments on commit 5c65c07

Please sign in to comment.