Comparing version 6.7.0-dev.20240615.sha.465ffd97 to 6.7.0-dev.20240618.sha.ec3cabaf
@@ -15,3 +15,2 @@ "use strict"; | ||
const count_1 = require("./operations/count"); | ||
const count_documents_1 = require("./operations/count_documents"); | ||
const delete_1 = require("./operations/delete"); | ||
@@ -460,3 +459,15 @@ const distinct_1 = require("./operations/distinct"); | ||
async countDocuments(filter = {}, options = {}) { | ||
return await (0, execute_operation_1.executeOperation)(this.client, new count_documents_1.CountDocumentsOperation(this, filter, (0, utils_1.resolveOptions)(this, options))); | ||
const pipeline = []; | ||
pipeline.push({ $match: filter }); | ||
if (typeof options.skip === 'number') { | ||
pipeline.push({ $skip: options.skip }); | ||
} | ||
if (typeof options.limit === 'number') { | ||
pipeline.push({ $limit: options.limit }); | ||
} | ||
pipeline.push({ $group: { _id: 1, n: { $sum: 1 } } }); | ||
const cursor = this.aggregate(pipeline, options); | ||
const doc = await cursor.next(); | ||
await cursor.close(); | ||
return doc?.n ?? 0; | ||
} | ||
@@ -463,0 +474,0 @@ async distinct(key, filter = {}, options = {}) { |
@@ -68,3 +68,3 @@ "use strict"; | ||
this.clientOptions = clientOptions; | ||
this.timeoutMS = options.defaultTimeoutMS ?? client.options?.timeoutMS; | ||
this.timeoutMS = options.defaultTimeoutMS ?? client.s.options?.timeoutMS; | ||
this.explicit = !!options.explicit; | ||
@@ -71,0 +71,0 @@ this[kServerSession] = this.explicit ? this.sessionPool.acquire() : null; |
{ | ||
"name": "mongodb", | ||
"version": "6.7.0-dev.20240615.sha.465ffd97", | ||
"version": "6.7.0-dev.20240618.sha.ec3cabaf", | ||
"description": "The official MongoDB driver for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -28,3 +28,2 @@ import { type BSONSerializeOptions, type Document, resolveBSONOptions } from './bson'; | ||
import { CountOperation, type CountOptions } from './operations/count'; | ||
import { CountDocumentsOperation, type CountDocumentsOptions } from './operations/count_documents'; | ||
import { | ||
@@ -106,2 +105,10 @@ DeleteManyOperation, | ||
/** @public */ | ||
export interface CountDocumentsOptions extends AggregateOptions { | ||
/** The number of documents to skip. */ | ||
skip?: number; | ||
/** The maximum amount of documents to consider. */ | ||
limit?: number; | ||
} | ||
/** @public */ | ||
export interface CollectionOptions extends BSONSerializeOptions, WriteConcernOptions { | ||
@@ -769,6 +776,19 @@ /** Specify a read concern for the collection. (only MongoDB 3.2 or higher supported) */ | ||
): Promise<number> { | ||
return await executeOperation( | ||
this.client, | ||
new CountDocumentsOperation(this as TODO_NODE_3286, filter, resolveOptions(this, options)) | ||
); | ||
const pipeline = []; | ||
pipeline.push({ $match: filter }); | ||
if (typeof options.skip === 'number') { | ||
pipeline.push({ $skip: options.skip }); | ||
} | ||
if (typeof options.limit === 'number') { | ||
pipeline.push({ $limit: options.limit }); | ||
} | ||
pipeline.push({ $group: { _id: 1, n: { $sum: 1 } } }); | ||
const cursor = this.aggregate<{ n: number }>(pipeline, options); | ||
const doc = await cursor.next(); | ||
await cursor.close(); | ||
return doc?.n ?? 0; | ||
} | ||
@@ -775,0 +795,0 @@ |
@@ -308,4 +308,9 @@ import { Admin } from './admin'; | ||
} from './cmap/wire_protocol/responses'; | ||
export type { CollectionOptions, CollectionPrivate, ModifyResult } from './collection'; | ||
export type { | ||
CollectionOptions, | ||
CollectionPrivate, | ||
CountDocumentsOptions, | ||
ModifyResult | ||
} from './collection'; | ||
export type { | ||
COMMAND_FAILED, | ||
@@ -467,3 +472,2 @@ COMMAND_STARTED, | ||
export type { CountOptions } from './operations/count'; | ||
export type { CountDocumentsOptions } from './operations/count_documents'; | ||
export type { | ||
@@ -470,0 +474,0 @@ ClusteredCollectionOptions, |
@@ -177,3 +177,3 @@ import { Binary, type Document, Long, type Timestamp } from './bson'; | ||
this.clientOptions = clientOptions; | ||
this.timeoutMS = options.defaultTimeoutMS ?? client.options?.timeoutMS; | ||
this.timeoutMS = options.defaultTimeoutMS ?? client.s.options?.timeoutMS; | ||
@@ -180,0 +180,0 @@ this.explicit = !!options.explicit; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3037109
387
62643