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

mongodb

Package Overview
Dependencies
Maintainers
8
Versions
563
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.20241019.sha.e9e8bf5b to 6.9.0-dev.20241021.sha.30c61f2a

3

lib/mongo_client.js

@@ -147,3 +147,4 @@ "use strict";

}
return await new executor_1.ClientBulkWriteExecutor(this, models, options).execute();
// We do not need schema type information past this point ("as any" is fine)
return await new executor_1.ClientBulkWriteExecutor(this, models, (0, utils_1.resolveOptions)(this, options)).execute();
}

@@ -150,0 +151,0 @@ /**

@@ -63,3 +63,3 @@ "use strict";

}
return { ok: 1 };
return results_merger_1.ClientBulkWriteResultsMerger.unacknowledged();
}

@@ -86,3 +86,3 @@ else {

bulkWriteError.cause = error;
bulkWriteError.partialResult = resultsMerger.result;
bulkWriteError.partialResult = resultsMerger.bulkWriteResult;
throw bulkWriteError;

@@ -103,6 +103,6 @@ }

error.writeErrors = resultsMerger.writeErrors;
error.partialResult = resultsMerger.result;
error.partialResult = resultsMerger.bulkWriteResult;
throw error;
}
return resultsMerger.result;
return resultsMerger.bulkWriteResult;
}

@@ -109,0 +109,0 @@ }

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

/**
* Unacknowledged bulk writes are always the same.
*/
const UNACKNOWLEDGED = {
acknowledged: false,
insertedCount: 0,
upsertedCount: 0,
matchedCount: 0,
modifiedCount: 0,
deletedCount: 0,
insertResults: undefined,
updateResults: undefined,
deleteResults: undefined
};
/**
* Merges client bulk write cursor responses together into a single result.

@@ -13,2 +27,8 @@ * @internal

/**
* @returns The standard unacknowledged bulk write result.
*/
static unacknowledged() {
return UNACKNOWLEDGED;
}
/**
* Instantiate the merger.

@@ -23,2 +43,3 @@ * @param options - The options.

this.result = {
acknowledged: true,
insertedCount: 0,

@@ -40,2 +61,18 @@ upsertedCount: 0,

/**
* Get the bulk write result object.
*/
get bulkWriteResult() {
return {
acknowledged: this.result.acknowledged,
insertedCount: this.result.insertedCount,
upsertedCount: this.result.upsertedCount,
matchedCount: this.result.matchedCount,
modifiedCount: this.result.modifiedCount,
deletedCount: this.result.deletedCount,
insertResults: this.result.insertResults,
updateResults: this.result.updateResults,
deleteResults: this.result.deleteResults
};
}
/**
* Merge the results in the cursor to the existing result.

@@ -42,0 +79,0 @@ * @param currentBatchOffset - The offset index to the original models.

{
"name": "mongodb",
"version": "6.9.0-dev.20241019.sha.e9e8bf5b",
"version": "6.9.0-dev.20241021.sha.30c61f2a",
"description": "The official MongoDB driver for Node.js",

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

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

ClientBulkWriteError,
ClientBulkWriteModel,
ClientBulkWriteOptions,

@@ -484,0 +485,0 @@ ClientBulkWriteResult,

@@ -34,3 +34,3 @@ import { promises as fs } from 'fs';

import {
type AnyClientBulkWriteModel,
type ClientBulkWriteModel,
type ClientBulkWriteOptions,

@@ -335,3 +335,2 @@ type ClientBulkWriteResult

/** @internal */
const kOptions = Symbol('options');

@@ -494,6 +493,6 @@

*/
async bulkWrite(
models: AnyClientBulkWriteModel[],
async bulkWrite<SchemaMap extends Record<string, Document> = Record<string, Document>>(
models: ReadonlyArray<ClientBulkWriteModel<SchemaMap>>,
options?: ClientBulkWriteOptions
): Promise<ClientBulkWriteResult | { ok: 1 }> {
): Promise<ClientBulkWriteResult> {
if (this.autoEncrypter) {

@@ -504,3 +503,8 @@ throw new MongoInvalidArgumentError(

}
return await new ClientBulkWriteExecutor(this, models, options).execute();
// We do not need schema type information past this point ("as any" is fine)
return await new ClientBulkWriteExecutor(
this,
models as any,
resolveOptions(this, options)
).execute();
}

@@ -507,0 +511,0 @@

@@ -39,3 +39,3 @@ import { BSON, type Document } from '../../bson';

export class ClientBulkWriteCommandBuilder {
models: AnyClientBulkWriteModel[];
models: ReadonlyArray<AnyClientBulkWriteModel<Document>>;
options: ClientBulkWriteOptions;

@@ -57,3 +57,3 @@ pkFactory: PkFactory;

constructor(
models: AnyClientBulkWriteModel[],
models: ReadonlyArray<AnyClientBulkWriteModel<Document>>,
options: ClientBulkWriteOptions,

@@ -253,3 +253,3 @@ pkFactory?: PkFactory

export const buildInsertOneOperation = (
model: ClientInsertOneModel,
model: ClientInsertOneModel<Document>,
index: number,

@@ -281,3 +281,6 @@ pkFactory: PkFactory

*/
export const buildDeleteOneOperation = (model: ClientDeleteOneModel, index: number): Document => {
export const buildDeleteOneOperation = (
model: ClientDeleteOneModel<Document>,
index: number
): Document => {
return createDeleteOperation(model, index, false);

@@ -292,3 +295,6 @@ };

*/
export const buildDeleteManyOperation = (model: ClientDeleteManyModel, index: number): Document => {
export const buildDeleteManyOperation = (
model: ClientDeleteManyModel<Document>,
index: number
): Document => {
return createDeleteOperation(model, index, true);

@@ -301,3 +307,3 @@ };

function createDeleteOperation(
model: ClientDeleteOneModel | ClientDeleteManyModel,
model: ClientDeleteOneModel<Document> | ClientDeleteManyModel<Document>,
index: number,

@@ -339,3 +345,3 @@ multi: boolean

export const buildUpdateOneOperation = (
model: ClientUpdateOneModel,
model: ClientUpdateOneModel<Document>,
index: number

@@ -353,3 +359,3 @@ ): ClientUpdateOperation => {

export const buildUpdateManyOperation = (
model: ClientUpdateManyModel,
model: ClientUpdateManyModel<Document>,
index: number

@@ -376,3 +382,3 @@ ): ClientUpdateOperation => {

function createUpdateOperation(
model: ClientUpdateOneModel | ClientUpdateManyModel,
model: ClientUpdateOneModel<Document> | ClientUpdateManyModel<Document>,
index: number,

@@ -425,3 +431,3 @@ multi: boolean

export const buildReplaceOneOperation = (
model: ClientReplaceOneModel,
model: ClientReplaceOneModel<Document>,
index: number

@@ -455,3 +461,3 @@ ): ClientReplaceOneOperation => {

export function buildOperation(
model: AnyClientBulkWriteModel,
model: AnyClientBulkWriteModel<Document>,
index: number,

@@ -458,0 +464,0 @@ pkFactory: PkFactory

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

export interface ClientWriteModel {
/** The namespace for the write. */
/**
* The namespace for the write.
*
* A namespace is a combination of the database name and the name of the collection: `<database-name>.<collection>`.
* All documents belong to a namespace.
*
* @see https://www.mongodb.com/docs/manual/reference/limits/#std-label-faq-dev-namespace
*/
namespace: string;

@@ -36,10 +43,10 @@ }

/** @public */
export interface ClientInsertOneModel extends ClientWriteModel {
export interface ClientInsertOneModel<TSchema> extends ClientWriteModel {
name: 'insertOne';
/** The document to insert. */
document: OptionalId<Document>;
document: OptionalId<TSchema>;
}
/** @public */
export interface ClientDeleteOneModel extends ClientWriteModel {
export interface ClientDeleteOneModel<TSchema> extends ClientWriteModel {
name: 'deleteOne';

@@ -50,3 +57,3 @@ /**

*/
filter: Filter<Document>;
filter: Filter<TSchema>;
/** Specifies a collation. */

@@ -59,3 +66,3 @@ collation?: CollationOptions;

/** @public */
export interface ClientDeleteManyModel extends ClientWriteModel {
export interface ClientDeleteManyModel<TSchema> extends ClientWriteModel {
name: 'deleteMany';

@@ -66,3 +73,3 @@ /**

*/
filter: Filter<Document>;
filter: Filter<TSchema>;
/** Specifies a collation. */

@@ -75,3 +82,3 @@ collation?: CollationOptions;

/** @public */
export interface ClientReplaceOneModel extends ClientWriteModel {
export interface ClientReplaceOneModel<TSchema> extends ClientWriteModel {
name: 'replaceOne';

@@ -82,5 +89,5 @@ /**

*/
filter: Filter<Document>;
filter: Filter<TSchema>;
/** The document with which to replace the matched document. */
replacement: WithoutId<Document>;
replacement: WithoutId<TSchema>;
/** Specifies a collation. */

@@ -95,3 +102,3 @@ collation?: CollationOptions;

/** @public */
export interface ClientUpdateOneModel extends ClientWriteModel {
export interface ClientUpdateOneModel<TSchema> extends ClientWriteModel {
name: 'updateOne';

@@ -102,3 +109,3 @@ /**

*/
filter: Filter<Document>;
filter: Filter<TSchema>;
/**

@@ -109,3 +116,3 @@ * The modifications to apply. The value can be either:

*/
update: UpdateFilter<Document> | Document[];
update: UpdateFilter<TSchema> | Document[];
/** A set of filters specifying to which array elements an update should apply. */

@@ -122,3 +129,3 @@ arrayFilters?: Document[];

/** @public */
export interface ClientUpdateManyModel extends ClientWriteModel {
export interface ClientUpdateManyModel<TSchema> extends ClientWriteModel {
name: 'updateMany';

@@ -129,3 +136,3 @@ /**

*/
filter: Filter<Document>;
filter: Filter<TSchema>;
/**

@@ -136,3 +143,3 @@ * The modifications to apply. The value can be either:

*/
update: UpdateFilter<Document> | Document[];
update: UpdateFilter<TSchema> | Document[];
/** A set of filters specifying to which array elements an update should apply. */

@@ -153,44 +160,77 @@ arrayFilters?: Document[];

*/
export type AnyClientBulkWriteModel =
| ClientInsertOneModel
| ClientReplaceOneModel
| ClientUpdateOneModel
| ClientUpdateManyModel
| ClientDeleteOneModel
| ClientDeleteManyModel;
export type AnyClientBulkWriteModel<TSchema extends Document> =
| ClientInsertOneModel<TSchema>
| ClientReplaceOneModel<TSchema>
| ClientUpdateOneModel<TSchema>
| ClientUpdateManyModel<TSchema>
| ClientDeleteOneModel<TSchema>
| ClientDeleteManyModel<TSchema>;
/**
* A mapping of namespace strings to collections schemas.
* @public
*
* @example
* ```ts
* type MongoDBSchemas = {
* 'db.books': Book;
* 'db.authors': Author;
* }
*
* const model: ClientBulkWriteModel<MongoDBSchemas> = {
* namespace: 'db.books'
* name: 'insertOne',
* document: { title: 'Practical MongoDB Aggregations', authorName: 3 } // error `authorName` cannot be number
* };
* ```
*
* The type of the `namespace` field narrows other parts of the BulkWriteModel to use the correct schema for type assertions.
*
*/
export type ClientBulkWriteModel<
SchemaMap extends Record<string, Document> = Record<string, Document>
> = {
[Namespace in keyof SchemaMap]: AnyClientBulkWriteModel<SchemaMap[Namespace]> & {
namespace: Namespace;
};
}[keyof SchemaMap];
/** @public */
export interface ClientBulkWriteResult {
/**
* Whether the bulk write was acknowledged.
*/
readonly acknowledged: boolean;
/**
* The total number of documents inserted across all insert operations.
*/
insertedCount: number;
readonly insertedCount: number;
/**
* The total number of documents upserted across all update operations.
*/
upsertedCount: number;
readonly upsertedCount: number;
/**
* The total number of documents matched across all update operations.
*/
matchedCount: number;
readonly matchedCount: number;
/**
* The total number of documents modified across all update operations.
*/
modifiedCount: number;
readonly modifiedCount: number;
/**
* The total number of documents deleted across all delete operations.
*/
deletedCount: number;
readonly deletedCount: number;
/**
* The results of each individual insert operation that was successfully performed.
*/
insertResults?: Map<number, ClientInsertOneResult>;
readonly insertResults?: ReadonlyMap<number, ClientInsertOneResult>;
/**
* The results of each individual update operation that was successfully performed.
*/
updateResults?: Map<number, ClientUpdateResult>;
readonly updateResults?: ReadonlyMap<number, ClientUpdateResult>;
/**
* The results of each individual delete operation that was successfully performed.
*/
deleteResults?: Map<number, ClientDeleteResult>;
readonly deleteResults?: ReadonlyMap<number, ClientDeleteResult>;
}

@@ -197,0 +237,0 @@

@@ -0,1 +1,3 @@

import { type Document } from 'bson';
import { ClientBulkWriteCursor } from '../../cursor/client_bulk_write_cursor';

@@ -25,5 +27,5 @@ import {

export class ClientBulkWriteExecutor {
client: MongoClient;
options: ClientBulkWriteOptions;
operations: AnyClientBulkWriteModel[];
private readonly client: MongoClient;
private readonly options: ClientBulkWriteOptions;
private readonly operations: ReadonlyArray<AnyClientBulkWriteModel<Document>>;

@@ -38,3 +40,3 @@ /**

client: MongoClient,
operations: AnyClientBulkWriteModel[],
operations: ReadonlyArray<AnyClientBulkWriteModel<Document>>,
options?: ClientBulkWriteOptions

@@ -80,3 +82,3 @@ ) {

*/
async execute(): Promise<ClientBulkWriteResult | { ok: 1 }> {
async execute(): Promise<ClientBulkWriteResult> {
// The command builder will take the user provided models and potential split the batch

@@ -96,3 +98,3 @@ // into multiple commands due to size.

}
return { ok: 1 };
return ClientBulkWriteResultsMerger.unacknowledged();
} else {

@@ -117,3 +119,3 @@ const resultsMerger = new ClientBulkWriteResultsMerger(this.options);

bulkWriteError.cause = error;
bulkWriteError.partialResult = resultsMerger.result;
bulkWriteError.partialResult = resultsMerger.bulkWriteResult;
throw bulkWriteError;

@@ -134,9 +136,9 @@ } else {

error.writeErrors = resultsMerger.writeErrors;
error.partialResult = resultsMerger.result;
error.partialResult = resultsMerger.bulkWriteResult;
throw error;
}
return resultsMerger.result;
return resultsMerger.bulkWriteResult;
}
}
}

@@ -15,2 +15,56 @@ import { MongoWriteConcernError } from '../..';

/**
* Unacknowledged bulk writes are always the same.
*/
const UNACKNOWLEDGED = {
acknowledged: false,
insertedCount: 0,
upsertedCount: 0,
matchedCount: 0,
modifiedCount: 0,
deletedCount: 0,
insertResults: undefined,
updateResults: undefined,
deleteResults: undefined
};
interface ClientBulkWriteResultAccumulation {
/**
* Whether the bulk write was acknowledged.
*/
acknowledged: boolean;
/**
* 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>;
}
/**
* Merges client bulk write cursor responses together into a single result.

@@ -20,5 +74,5 @@ * @internal

export class ClientBulkWriteResultsMerger {
result: ClientBulkWriteResult;
options: ClientBulkWriteOptions;
currentBatchOffset: number;
private result: ClientBulkWriteResultAccumulation;
private options: ClientBulkWriteOptions;
private currentBatchOffset: number;
writeConcernErrors: Document[];

@@ -28,2 +82,9 @@ writeErrors: Map<number, ClientBulkWriteError>;

/**
* @returns The standard unacknowledged bulk write result.
*/
static unacknowledged(): ClientBulkWriteResult {
return UNACKNOWLEDGED;
}
/**
* Instantiate the merger.

@@ -38,2 +99,3 @@ * @param options - The options.

this.result = {
acknowledged: true,
insertedCount: 0,

@@ -57,2 +119,19 @@ upsertedCount: 0,

/**
* Get the bulk write result object.
*/
get bulkWriteResult(): ClientBulkWriteResult {
return {
acknowledged: this.result.acknowledged,
insertedCount: this.result.insertedCount,
upsertedCount: this.result.upsertedCount,
matchedCount: this.result.matchedCount,
modifiedCount: this.result.modifiedCount,
deletedCount: this.result.deletedCount,
insertResults: this.result.insertResults,
updateResults: this.result.updateResults,
deleteResults: this.result.deleteResults
};
}
/**
* Merge the results in the cursor to the existing result.

@@ -59,0 +138,0 @@ * @param currentBatchOffset - The offset index to the original models.

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 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