You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

mongodb

Package Overview
Dependencies
Maintainers
0
Versions
691
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

to
6.18.0-dev.20250802.sha.be7f808c

11

lib/collection.js

@@ -306,6 +306,11 @@ "use strict";

async findOne(filter = {}, options = {}) {
const cursor = this.find(filter, options).limit(-1).batchSize(1);
const res = await cursor.next();
// Explicitly set the limit to 1 and singleBatch to true for all commands, per the spec.
// noCursorTimeout must be unset as well as batchSize.
// See: https://github.com/mongodb/specifications/blob/master/source/crud/crud.md#findone-api-details
const { batchSize: _batchSize, noCursorTimeout: _noCursorTimeout, ...opts } = options;
opts.singleBatch = true;
const cursor = this.find(filter, opts).limit(1);
const result = await cursor.next();
await cursor.close();
return res;
return result;
}

@@ -312,0 +317,0 @@ find(filter = {}, options = {}) {

@@ -184,4 +184,5 @@ "use strict";

throw previousOperationError;
if (hasReadAspect && !(0, error_1.isRetryableReadError)(previousOperationError))
if (hasReadAspect && !(0, error_1.isRetryableReadError)(previousOperationError)) {
throw previousOperationError;
}
if (previousOperationError instanceof error_1.MongoNetworkError &&

@@ -188,0 +189,0 @@ operation.hasAspect(operation_1.Aspect.CURSOR_CREATING) &&

@@ -83,11 +83,13 @@ "use strict";

if (options.batchSize < 0) {
if (options.limit &&
options.limit !== 0 &&
Math.abs(options.batchSize) < Math.abs(options.limit)) {
findCommand.limit = -options.batchSize;
}
findCommand.singleBatch = true;
findCommand.limit = -options.batchSize;
}
else {
findCommand.batchSize = options.batchSize;
if (options.batchSize === options.limit) {
// Spec dictates that if these are equal the batchSize should be one more than the
// limit to avoid leaving the cursor open.
findCommand.batchSize = options.batchSize + 1;
}
else {
findCommand.batchSize = options.batchSize;
}
}

@@ -94,0 +96,0 @@ }

{
"name": "mongodb",
"version": "6.18.0-dev.20250801.sha.aac76296",
"version": "6.18.0-dev.20250802.sha.be7f808c",
"description": "The official MongoDB driver for Node.js",

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

@@ -46,3 +46,3 @@ import { type BSONSerializeOptions, type Document, resolveBSONOptions } from './bson';

import { autoConnect, executeOperation } from './operations/execute_operation';
import type { FindOptions } from './operations/find';
import { type FindOneOptions, type FindOptions } from './operations/find';
import {

@@ -540,3 +540,3 @@ FindOneAndDeleteOperation,

filter: Filter<TSchema>,
options: Omit<FindOptions, 'timeoutMode'> & Abortable
options: Omit<FindOneOptions, 'timeoutMode'> & Abortable
): Promise<WithId<TSchema> | null>;

@@ -549,3 +549,3 @@

filter: Filter<TSchema>,
options?: Omit<FindOptions, 'timeoutMode'> & Abortable
options?: Omit<FindOneOptions, 'timeoutMode'> & Abortable
): Promise<T | null>;

@@ -555,8 +555,13 @@

filter: Filter<TSchema> = {},
options: FindOptions & Abortable = {}
options: Omit<FindOneOptions, 'timeoutMode'> & Abortable = {}
): Promise<WithId<TSchema> | null> {
const cursor = this.find(filter, options).limit(-1).batchSize(1);
const res = await cursor.next();
// Explicitly set the limit to 1 and singleBatch to true for all commands, per the spec.
// noCursorTimeout must be unset as well as batchSize.
// See: https://github.com/mongodb/specifications/blob/master/source/crud/crud.md#findone-api-details
const { batchSize: _batchSize, noCursorTimeout: _noCursorTimeout, ...opts } = options;
opts.singleBatch = true;
const cursor = this.find(filter, opts).limit(1);
const result = await cursor.next();
await cursor.close();
return res;
return result;
}

@@ -563,0 +568,0 @@

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

export type { EstimatedDocumentCountOptions } from './operations/estimated_document_count';
export type { FindOptions } from './operations/find';
export type { FindOneOptions, FindOptions } from './operations/find';
export type {

@@ -529,0 +529,0 @@ FindOneAndDeleteOptions,

@@ -251,4 +251,5 @@ import {

if (hasReadAspect && !isRetryableReadError(previousOperationError))
if (hasReadAspect && !isRetryableReadError(previousOperationError)) {
throw previousOperationError;
}

@@ -255,0 +256,0 @@ if (

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

/** @public */
export interface FindOneOptions extends FindOptions {
/** @deprecated Will be removed in the next major version. User provided value will be ignored. */
batchSize?: number;
/** @deprecated Will be removed in the next major version. User provided value will be ignored. */
limit?: number;
/** @deprecated Will be removed in the next major version. User provided value will be ignored. */
noCursorTimeout?: boolean;
}
/** @internal */

@@ -189,13 +199,11 @@ export class FindOperation extends CommandOperation<CursorResponse> {

if (options.batchSize < 0) {
if (
options.limit &&
options.limit !== 0 &&
Math.abs(options.batchSize) < Math.abs(options.limit)
) {
findCommand.limit = -options.batchSize;
findCommand.limit = -options.batchSize;
} else {
if (options.batchSize === options.limit) {
// Spec dictates that if these are equal the batchSize should be one more than the
// limit to avoid leaving the cursor open.
findCommand.batchSize = options.batchSize + 1;
} else {
findCommand.batchSize = options.batchSize;
}
findCommand.singleBatch = true;
} else {
findCommand.batchSize = options.batchSize;
}

@@ -202,0 +210,0 @@ }

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 too big to display