Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongodb

Package Overview
Dependencies
Maintainers
8
Versions
574
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb - npm Package Compare versions

Comparing version 6.9.0-dev.20240918.sha.643a8755 to 6.9.0-dev.20240926.sha.3d3da407

lib/cursor/client_bulk_write_cursor.js

11

lib/cmap/command_monitoring_events.js

@@ -171,3 +171,12 @@ "use strict";

if (command instanceof commands_1.OpMsgRequest) {
return (0, utils_1.deepCopy)(command.command);
const cmd = (0, utils_1.deepCopy)(command.command);
// For OP_MSG with payload type 1 we need to pull the documents
// array out of the document sequence for monitoring.
if (cmd.ops instanceof commands_1.DocumentSequence) {
cmd.ops = cmd.ops.documents;
}
if (cmd.nsInfo instanceof commands_1.DocumentSequence) {
cmd.nsInfo = cmd.nsInfo.documents;
}
return cmd;
}

@@ -174,0 +183,0 @@ if (command.query?.$query) {

8

lib/cmap/commands.js

@@ -356,6 +356,6 @@ "use strict";

// Document sequences starts with type 1 at the first byte.
const buffer = Buffer.allocUnsafe(1 + 4 + key.length);
const buffer = Buffer.allocUnsafe(1 + 4 + key.length + 1);
buffer[0] = 1;
// Third part is the field name at offset 5.
encodeUTF8Into(buffer, key, 5);
// Third part is the field name at offset 5 with trailing null byte.
encodeUTF8Into(buffer, `${key}\0`, 5);
chunks.push(buffer);

@@ -370,3 +370,3 @@ // Fourth part are the documents' bytes.

// Second part of the sequence is the length at offset 1;
buffer.writeInt32LE(key.length + docsLength, 1);
buffer.writeInt32LE(4 + key.length + 1 + docsLength, 1);
// Why are we removing the field from the command? This is because it needs to be

@@ -373,0 +373,0 @@ // removed in the OP_MSG request first section, and DocumentSequence is not a

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExplainedCursorResponse = exports.CursorResponse = exports.MongoDBResponse = void 0;
exports.ClientBulkWriteCursorResponse = exports.ExplainedCursorResponse = exports.CursorResponse = exports.MongoDBResponse = void 0;
exports.isErrorResponse = isErrorResponse;

@@ -255,2 +255,24 @@ const bson_1 = require("../../bson");

exports.ExplainedCursorResponse = ExplainedCursorResponse;
/**
* Client bulk writes have some extra metadata at the top level that needs to be
* included in the result returned to the user.
*/
class ClientBulkWriteCursorResponse extends CursorResponse {
get insertedCount() {
return this.get('nInserted', bson_1.BSONType.int, true);
}
get upsertedCount() {
return this.get('nUpserted', bson_1.BSONType.int, true);
}
get matchedCount() {
return this.get('nMatched', bson_1.BSONType.int, true);
}
get modifiedCount() {
return this.get('nModified', bson_1.BSONType.int, true);
}
get deletedCount() {
return this.get('nDeleted', bson_1.BSONType.int, true);
}
}
exports.ClientBulkWriteCursorResponse = ClientBulkWriteCursorResponse;
//# sourceMappingURL=responses.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MongoWriteConcernError = exports.MongoServerSelectionError = exports.MongoSystemError = exports.MongoMissingDependencyError = exports.MongoMissingCredentialsError = exports.MongoCompatibilityError = exports.MongoInvalidArgumentError = exports.MongoParseError = exports.MongoNetworkTimeoutError = exports.MongoNetworkError = exports.MongoTopologyClosedError = exports.MongoCursorExhaustedError = exports.MongoServerClosedError = exports.MongoCursorInUseError = exports.MongoUnexpectedServerResponseError = exports.MongoGridFSChunkError = exports.MongoGridFSStreamError = exports.MongoTailableCursorError = exports.MongoChangeStreamError = exports.MongoGCPError = exports.MongoAzureError = exports.MongoOIDCError = exports.MongoAWSError = exports.MongoKerberosError = exports.MongoExpiredSessionError = exports.MongoTransactionError = exports.MongoNotConnectedError = exports.MongoDecompressionError = exports.MongoBatchReExecutionError = exports.MongoRuntimeError = exports.MongoAPIError = exports.MongoDriverError = exports.MongoServerError = exports.MongoError = exports.MongoErrorLabel = exports.GET_MORE_RESUMABLE_CODES = exports.MONGODB_ERROR_CODES = exports.NODE_IS_RECOVERING_ERROR_MESSAGE = exports.LEGACY_NOT_PRIMARY_OR_SECONDARY_ERROR_MESSAGE = exports.LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE = void 0;
exports.MongoWriteConcernError = exports.MongoServerSelectionError = exports.MongoSystemError = exports.MongoMissingDependencyError = exports.MongoMissingCredentialsError = exports.MongoCompatibilityError = exports.MongoInvalidArgumentError = exports.MongoParseError = exports.MongoNetworkTimeoutError = exports.MongoNetworkError = exports.MongoTopologyClosedError = exports.MongoCursorExhaustedError = exports.MongoServerClosedError = exports.MongoCursorInUseError = exports.MongoUnexpectedServerResponseError = exports.MongoGridFSChunkError = exports.MongoGridFSStreamError = exports.MongoTailableCursorError = exports.MongoChangeStreamError = exports.MongoBulkWriteCursorError = exports.MongoGCPError = exports.MongoAzureError = exports.MongoOIDCError = exports.MongoAWSError = exports.MongoKerberosError = exports.MongoExpiredSessionError = exports.MongoTransactionError = exports.MongoNotConnectedError = exports.MongoDecompressionError = exports.MongoBatchReExecutionError = exports.MongoRuntimeError = exports.MongoAPIError = exports.MongoDriverError = exports.MongoServerError = exports.MongoError = exports.MongoErrorLabel = exports.GET_MORE_RESUMABLE_CODES = exports.MONGODB_ERROR_CODES = exports.NODE_IS_RECOVERING_ERROR_MESSAGE = exports.LEGACY_NOT_PRIMARY_OR_SECONDARY_ERROR_MESSAGE = exports.LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE = void 0;
exports.isNetworkErrorBeforeHandshake = isNetworkErrorBeforeHandshake;

@@ -554,2 +554,28 @@ exports.needsRetryableWriteLabel = needsRetryableWriteLabel;

/**
* An error indicating that an error occurred when processing bulk write results.
*
* @public
* @category Error
*/
class MongoBulkWriteCursorError extends MongoRuntimeError {
/**
* **Do not use this constructor!**
*
* Meant for internal use only.
*
* @remarks
* This class is only meant to be constructed within the driver. This constructor is
* not subject to semantic versioning compatibility guarantees and may change at any time.
*
* @public
**/
constructor(message) {
super(message);
}
get name() {
return 'MongoBulkWriteCursorError';
}
}
exports.MongoBulkWriteCursorError = MongoBulkWriteCursorError;
/**
* An error generated when a ChangeStream operation fails to execute.

@@ -556,0 +582,0 @@ *

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MongoTopologyClosedError = exports.MongoTailableCursorError = exports.MongoSystemError = exports.MongoServerSelectionError = exports.MongoServerError = exports.MongoServerClosedError = exports.MongoRuntimeError = exports.MongoParseError = exports.MongoOIDCError = exports.MongoNotConnectedError = exports.MongoNetworkTimeoutError = exports.MongoNetworkError = exports.MongoMissingDependencyError = exports.MongoMissingCredentialsError = exports.MongoKerberosError = exports.MongoInvalidArgumentError = exports.MongoGridFSStreamError = exports.MongoGridFSChunkError = exports.MongoGCPError = exports.MongoExpiredSessionError = exports.MongoError = exports.MongoDriverError = exports.MongoDecompressionError = exports.MongoCursorInUseError = exports.MongoCursorExhaustedError = exports.MongoCompatibilityError = exports.MongoChangeStreamError = exports.MongoBatchReExecutionError = exports.MongoAzureError = exports.MongoAWSError = exports.MongoAPIError = exports.ChangeStreamCursor = exports.ClientEncryption = exports.MongoBulkWriteError = exports.UUID = exports.Timestamp = exports.ObjectId = exports.MinKey = exports.MaxKey = exports.Long = exports.Int32 = exports.Double = exports.Decimal128 = exports.DBRef = exports.Code = exports.BSONType = exports.BSONSymbol = exports.BSONRegExp = exports.Binary = exports.BSON = void 0;
exports.ConnectionPoolClosedEvent = exports.ConnectionPoolClearedEvent = exports.ConnectionCreatedEvent = exports.ConnectionClosedEvent = exports.ConnectionCheckOutStartedEvent = exports.ConnectionCheckOutFailedEvent = exports.ConnectionCheckedOutEvent = exports.ConnectionCheckedInEvent = exports.CommandSucceededEvent = exports.CommandStartedEvent = exports.CommandFailedEvent = exports.WriteConcern = exports.ReadPreference = exports.ReadConcern = exports.TopologyType = exports.ServerType = exports.ReadPreferenceMode = exports.ReadConcernLevel = exports.ProfilingLevel = exports.ReturnDocument = exports.ServerApiVersion = exports.ExplainVerbosity = exports.MongoErrorLabel = exports.CURSOR_FLAGS = exports.Compressor = exports.AuthMechanism = exports.GSSAPICanonicalizationValue = exports.AutoEncryptionLoggerLevel = exports.BatchType = exports.UnorderedBulkOperation = exports.OrderedBulkOperation = exports.MongoClient = exports.ListIndexesCursor = exports.ListCollectionsCursor = exports.GridFSBucketWriteStream = exports.GridFSBucketReadStream = exports.GridFSBucket = exports.FindCursor = exports.Db = exports.Collection = exports.ClientSession = exports.ChangeStream = exports.CancellationToken = exports.AggregationCursor = exports.Admin = exports.AbstractCursor = exports.configureExplicitResourceManagement = exports.MongoWriteConcernError = exports.MongoUnexpectedServerResponseError = exports.MongoTransactionError = void 0;
exports.MongoClientAuthProviders = exports.MongoCryptKMSRequestNetworkTimeoutError = exports.MongoCryptInvalidArgumentError = exports.MongoCryptError = exports.MongoCryptCreateEncryptedCollectionError = exports.MongoCryptCreateDataKeyError = exports.MongoCryptAzureKMSRequestError = exports.SrvPollingEvent = exports.WaitingForSuitableServerEvent = exports.ServerSelectionSucceededEvent = exports.ServerSelectionStartedEvent = exports.ServerSelectionFailedEvent = exports.ServerSelectionEvent = exports.TopologyOpeningEvent = exports.TopologyDescriptionChangedEvent = exports.TopologyClosedEvent = exports.ServerOpeningEvent = exports.ServerHeartbeatSucceededEvent = exports.ServerHeartbeatStartedEvent = exports.ServerHeartbeatFailedEvent = exports.ServerDescriptionChangedEvent = exports.ServerClosedEvent = exports.ConnectionReadyEvent = exports.ConnectionPoolReadyEvent = exports.ConnectionPoolMonitoringEvent = exports.ConnectionPoolCreatedEvent = void 0;
exports.MongoTailableCursorError = exports.MongoSystemError = exports.MongoServerSelectionError = exports.MongoServerError = exports.MongoServerClosedError = exports.MongoRuntimeError = exports.MongoParseError = exports.MongoOIDCError = exports.MongoNotConnectedError = exports.MongoNetworkTimeoutError = exports.MongoNetworkError = exports.MongoMissingDependencyError = exports.MongoMissingCredentialsError = exports.MongoKerberosError = exports.MongoInvalidArgumentError = exports.MongoGridFSStreamError = exports.MongoGridFSChunkError = exports.MongoGCPError = exports.MongoExpiredSessionError = exports.MongoError = exports.MongoDriverError = exports.MongoDecompressionError = exports.MongoCursorInUseError = exports.MongoCursorExhaustedError = exports.MongoCompatibilityError = exports.MongoChangeStreamError = exports.MongoBulkWriteCursorError = exports.MongoBatchReExecutionError = exports.MongoAzureError = exports.MongoAWSError = exports.MongoAPIError = exports.ChangeStreamCursor = exports.ClientEncryption = exports.MongoBulkWriteError = exports.UUID = exports.Timestamp = exports.ObjectId = exports.MinKey = exports.MaxKey = exports.Long = exports.Int32 = exports.Double = exports.Decimal128 = exports.DBRef = exports.Code = exports.BSONType = exports.BSONSymbol = exports.BSONRegExp = exports.Binary = exports.BSON = void 0;
exports.ConnectionPoolClearedEvent = exports.ConnectionCreatedEvent = exports.ConnectionClosedEvent = exports.ConnectionCheckOutStartedEvent = exports.ConnectionCheckOutFailedEvent = exports.ConnectionCheckedOutEvent = exports.ConnectionCheckedInEvent = exports.CommandSucceededEvent = exports.CommandStartedEvent = exports.CommandFailedEvent = exports.WriteConcern = exports.ReadPreference = exports.ReadConcern = exports.TopologyType = exports.ServerType = exports.ReadPreferenceMode = exports.ReadConcernLevel = exports.ProfilingLevel = exports.ReturnDocument = exports.ServerApiVersion = exports.ExplainVerbosity = exports.MongoErrorLabel = exports.CURSOR_FLAGS = exports.Compressor = exports.AuthMechanism = exports.GSSAPICanonicalizationValue = exports.AutoEncryptionLoggerLevel = exports.BatchType = exports.UnorderedBulkOperation = exports.OrderedBulkOperation = exports.MongoClient = exports.ListIndexesCursor = exports.ListCollectionsCursor = exports.GridFSBucketWriteStream = exports.GridFSBucketReadStream = exports.GridFSBucket = exports.FindCursor = exports.Db = exports.Collection = exports.ClientSession = exports.ChangeStream = exports.CancellationToken = exports.AggregationCursor = exports.Admin = exports.AbstractCursor = exports.configureExplicitResourceManagement = exports.MongoWriteConcernError = exports.MongoUnexpectedServerResponseError = exports.MongoTransactionError = exports.MongoTopologyClosedError = void 0;
exports.MongoClientAuthProviders = exports.MongoCryptKMSRequestNetworkTimeoutError = exports.MongoCryptInvalidArgumentError = exports.MongoCryptError = exports.MongoCryptCreateEncryptedCollectionError = exports.MongoCryptCreateDataKeyError = exports.MongoCryptAzureKMSRequestError = exports.SrvPollingEvent = exports.WaitingForSuitableServerEvent = exports.ServerSelectionSucceededEvent = exports.ServerSelectionStartedEvent = exports.ServerSelectionFailedEvent = exports.ServerSelectionEvent = exports.TopologyOpeningEvent = exports.TopologyDescriptionChangedEvent = exports.TopologyClosedEvent = exports.ServerOpeningEvent = exports.ServerHeartbeatSucceededEvent = exports.ServerHeartbeatStartedEvent = exports.ServerHeartbeatFailedEvent = exports.ServerDescriptionChangedEvent = exports.ServerClosedEvent = exports.ConnectionReadyEvent = exports.ConnectionPoolReadyEvent = exports.ConnectionPoolMonitoringEvent = exports.ConnectionPoolCreatedEvent = exports.ConnectionPoolClosedEvent = void 0;
const admin_1 = require("./admin");

@@ -70,2 +70,3 @@ Object.defineProperty(exports, "Admin", { enumerable: true, get: function () { return admin_1.Admin; } });

Object.defineProperty(exports, "MongoBatchReExecutionError", { enumerable: true, get: function () { return error_1.MongoBatchReExecutionError; } });
Object.defineProperty(exports, "MongoBulkWriteCursorError", { enumerable: true, get: function () { return error_1.MongoBulkWriteCursorError; } });
Object.defineProperty(exports, "MongoChangeStreamError", { enumerable: true, get: function () { return error_1.MongoChangeStreamError; } });

@@ -72,0 +73,0 @@ Object.defineProperty(exports, "MongoCompatibilityError", { enumerable: true, get: function () { return error_1.MongoCompatibilityError; } });

@@ -16,2 +16,3 @@ "use strict";

const mongo_types_1 = require("./mongo_types");
const executor_1 = require("./operations/client_bulk_write/executor");
const execute_operation_1 = require("./operations/execute_operation");

@@ -138,2 +139,11 @@ const run_command_1 = require("./operations/run_command");

/**
* Executes a client bulk write operation, available on server 8.0+.
* @param models - The client bulk write models.
* @param options - The client bulk write options.
* @returns A ClientBulkWriteResult for acknowledged writes and ok: 1 for unacknowledged writes.
*/
async bulkWrite(models, options) {
return await new executor_1.ClientBulkWriteExecutor(this, models, options).execute();
}
/**
* Connect to MongoDB using a url

@@ -140,0 +150,0 @@ *

@@ -6,2 +6,3 @@ "use strict";

const commands_1 = require("../../cmap/commands");
const utils_1 = require("../../utils");
/** @internal */

@@ -13,5 +14,6 @@ class ClientBulkWriteCommandBuilder {

*/
constructor(models, options) {
constructor(models, options, pkFactory) {
this.models = models;
this.options = options;
this.pkFactory = pkFactory ?? utils_1.DEFAULT_PK_FACTORY;
}

@@ -40,7 +42,7 @@ /**

if (index != null) {
operations.push(buildOperation(model, index));
operations.push(buildOperation(model, index, this.pkFactory));
}
else {
namespaces.set(ns, currentNamespaceIndex);
operations.push(buildOperation(model, currentNamespaceIndex));
operations.push(buildOperation(model, currentNamespaceIndex, this.pkFactory));
currentNamespaceIndex++;

@@ -66,2 +68,7 @@ }

}
// we check for undefined specifically here to allow falsy values
// eslint-disable-next-line no-restricted-syntax
if (this.options.comment !== undefined) {
command.comment = this.options.comment;
}
return [command];

@@ -77,3 +84,3 @@ }

*/
const buildInsertOneOperation = (model, index) => {
const buildInsertOneOperation = (model, index, pkFactory) => {
const document = {

@@ -83,2 +90,3 @@ insert: index,

};
document.document._id = model.document._id ?? pkFactory.createPk();
return document;

@@ -163,2 +171,5 @@ };

}
if (model.collation) {
document.collation = model.collation;
}
return document;

@@ -185,2 +196,5 @@ }

}
if (model.collation) {
document.collation = model.collation;
}
return document;

@@ -190,6 +204,6 @@ };

/** @internal */
function buildOperation(model, index) {
function buildOperation(model, index, pkFactory) {
switch (model.name) {
case 'insertOne':
return (0, exports.buildInsertOneOperation)(model, index);
return (0, exports.buildInsertOneOperation)(model, index, pkFactory);
case 'deleteOne':

@@ -196,0 +210,0 @@ return (0, exports.buildDeleteOneOperation)(model, index);

{
"name": "mongodb",
"version": "6.9.0-dev.20240918.sha.643a8755",
"version": "6.9.0-dev.20240926.sha.3d3da407",
"description": "The official MongoDB driver for Node.js",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -10,3 +10,8 @@ import { type Document, type ObjectId } from '../bson';

import { calculateDurationInMs, deepCopy } from '../utils';
import { OpMsgRequest, type OpQueryRequest, type WriteProtocolMessageType } from './commands';
import {
DocumentSequence,
OpMsgRequest,
type OpQueryRequest,
type WriteProtocolMessageType
} from './commands';
import type { Connection } from './connection';

@@ -253,3 +258,12 @@

if (command instanceof OpMsgRequest) {
return deepCopy(command.command);
const cmd = deepCopy(command.command);
// For OP_MSG with payload type 1 we need to pull the documents
// array out of the document sequence for monitoring.
if (cmd.ops instanceof DocumentSequence) {
cmd.ops = cmd.ops.documents;
}
if (cmd.nsInfo instanceof DocumentSequence) {
cmd.nsInfo = cmd.nsInfo.documents;
}
return cmd;
}

@@ -256,0 +270,0 @@

@@ -547,6 +547,6 @@ import type { BSONSerializeOptions, Document, Long } from '../bson';

// Document sequences starts with type 1 at the first byte.
const buffer = Buffer.allocUnsafe(1 + 4 + key.length);
const buffer = Buffer.allocUnsafe(1 + 4 + key.length + 1);
buffer[0] = 1;
// Third part is the field name at offset 5.
encodeUTF8Into(buffer, key, 5);
// Third part is the field name at offset 5 with trailing null byte.
encodeUTF8Into(buffer, `${key}\0`, 5);
chunks.push(buffer);

@@ -561,3 +561,3 @@ // Fourth part are the documents' bytes.

// Second part of the sequence is the length at offset 1;
buffer.writeInt32LE(key.length + docsLength, 1);
buffer.writeInt32LE(4 + key.length + 1 + docsLength, 1);
// Why are we removing the field from the command? This is because it needs to be

@@ -564,0 +564,0 @@ // removed in the OP_MSG request first section, and DocumentSequence is not a

@@ -332,1 +332,27 @@ import { type DeserializeOptions } from 'bson';

}
/**
* Client bulk writes have some extra metadata at the top level that needs to be
* included in the result returned to the user.
*/
export class ClientBulkWriteCursorResponse extends CursorResponse {
get insertedCount() {
return this.get('nInserted', BSONType.int, true);
}
get upsertedCount() {
return this.get('nUpserted', BSONType.int, true);
}
get matchedCount() {
return this.get('nMatched', BSONType.int, true);
}
get modifiedCount() {
return this.get('nModified', BSONType.int, true);
}
get deletedCount() {
return this.get('nDeleted', BSONType.int, true);
}
}

@@ -620,2 +620,29 @@ import type { Document } from './bson';

/**
* An error indicating that an error occurred when processing bulk write results.
*
* @public
* @category Error
*/
export class MongoBulkWriteCursorError extends MongoRuntimeError {
/**
* **Do not use this constructor!**
*
* Meant for internal use only.
*
* @remarks
* This class is only meant to be constructed within the driver. This constructor is
* not subject to semantic versioning compatibility guarantees and may change at any time.
*
* @public
**/
constructor(message: string) {
super(message);
}
override get name(): string {
return 'MongoBulkWriteCursorError';
}
}
/**
* An error generated when a ChangeStream operation fails to execute.

@@ -622,0 +649,0 @@ *

@@ -47,2 +47,3 @@ import { Admin } from './admin';

MongoBatchReExecutionError,
MongoBulkWriteCursorError,
MongoChangeStreamError,

@@ -478,2 +479,17 @@ MongoCompatibilityError,

export type {
AnyClientBulkWriteModel,
ClientBulkWriteOptions,
ClientBulkWriteResult,
ClientDeleteManyModel,
ClientDeleteOneModel,
ClientDeleteResult,
ClientInsertOneModel,
ClientInsertOneResult,
ClientReplaceOneModel,
ClientUpdateManyModel,
ClientUpdateOneModel,
ClientUpdateResult,
ClientWriteModel
} from './operations/client_bulk_write/common';
export type {
CollationOptions,

@@ -480,0 +496,0 @@ CommandOperation,

@@ -33,2 +33,8 @@ import { promises as fs } from 'fs';

import { TypedEventEmitter } from './mongo_types';
import {
type AnyClientBulkWriteModel,
type ClientBulkWriteOptions,
type ClientBulkWriteResult
} from './operations/client_bulk_write/common';
import { ClientBulkWriteExecutor } from './operations/client_bulk_write/executor';
import { executeOperation } from './operations/execute_operation';

@@ -482,2 +488,15 @@ import { RunAdminCommandOperation } from './operations/run_command';

/**
* Executes a client bulk write operation, available on server 8.0+.
* @param models - The client bulk write models.
* @param options - The client bulk write options.
* @returns A ClientBulkWriteResult for acknowledged writes and ok: 1 for unacknowledged writes.
*/
async bulkWrite(
models: AnyClientBulkWriteModel[],
options?: ClientBulkWriteOptions
): Promise<ClientBulkWriteResult | { ok: 1 }> {
return await new ClientBulkWriteExecutor(this, models, options).execute();
}
/**
* Connect to MongoDB using a url

@@ -484,0 +503,0 @@ *

import { type Document } from '../../bson';
import { DocumentSequence } from '../../cmap/commands';
import { type PkFactory } from '../../mongo_client';
import type { Filter, OptionalId, UpdateFilter, WithoutId } from '../../mongo_types';
import { DEFAULT_PK_FACTORY } from '../../utils';
import { type CollationOptions } from '../command';

@@ -26,2 +28,3 @@ import { type Hint } from '../operation';

let?: Document;
comment?: any;
}

@@ -33,2 +36,3 @@

options: ClientBulkWriteOptions;
pkFactory: PkFactory;

@@ -39,5 +43,10 @@ /**

*/
constructor(models: AnyClientBulkWriteModel[], options: ClientBulkWriteOptions) {
constructor(
models: AnyClientBulkWriteModel[],
options: ClientBulkWriteOptions,
pkFactory?: PkFactory
) {
this.models = models;
this.options = options;
this.pkFactory = pkFactory ?? DEFAULT_PK_FACTORY;
}

@@ -68,6 +77,6 @@

if (index != null) {
operations.push(buildOperation(model, index));
operations.push(buildOperation(model, index, this.pkFactory));
} else {
namespaces.set(ns, currentNamespaceIndex);
operations.push(buildOperation(model, currentNamespaceIndex));
operations.push(buildOperation(model, currentNamespaceIndex, this.pkFactory));
currentNamespaceIndex++;

@@ -95,2 +104,8 @@ }

}
// we check for undefined specifically here to allow falsy values
// eslint-disable-next-line no-restricted-syntax
if (this.options.comment !== undefined) {
command.comment = this.options.comment;
}
return [command];

@@ -114,3 +129,4 @@ }

model: ClientInsertOneModel,
index: number
index: number,
pkFactory: PkFactory
): ClientInsertOperation => {

@@ -121,2 +137,3 @@ const document: ClientInsertOperation = {

};
document.document._id = model.document._id ?? pkFactory.createPk();
return document;

@@ -185,2 +202,3 @@ };

arrayFilters?: Document[];
collation?: CollationOptions;
}

@@ -237,2 +255,5 @@

}
if (model.collation) {
document.collation = model.collation;
}
return document;

@@ -249,2 +270,3 @@ }

upsert?: boolean;
collation?: CollationOptions;
}

@@ -274,2 +296,5 @@

}
if (model.collation) {
document.collation = model.collation;
}
return document;

@@ -279,6 +304,10 @@ };

/** @internal */
export function buildOperation(model: AnyClientBulkWriteModel, index: number): Document {
export function buildOperation(
model: AnyClientBulkWriteModel,
index: number,
pkFactory: PkFactory
): Document {
switch (model.name) {
case 'insertOne':
return buildInsertOneOperation(model, index);
return buildInsertOneOperation(model, index, pkFactory);
case 'deleteOne':

@@ -285,0 +314,0 @@ return buildDeleteOneOperation(model, index);

@@ -147,1 +147,80 @@ import { type Document } from '../../bson';

| ClientDeleteManyModel;
/** @public */
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;
/**
* 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>;
}
/** @public */
export interface ClientInsertOneResult {
/**
* The _id of the inserted document.
*/
insertedId: any;
}
/** @public */
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;
/**
* Determines if the upsert did include an _id, which includes the case of the _id being null.
*/
didUpsert: boolean;
}
/** @public */
export interface ClientDeleteResult {
/**
* The number of documents that were deleted.
*/
deletedCount: number;
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc