First commit
This commit is contained in:
679
node_modules/mongodb/lib/cursor/abstract_cursor.js
generated
vendored
Normal file
679
node_modules/mongodb/lib/cursor/abstract_cursor.js
generated
vendored
Normal file
@@ -0,0 +1,679 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.assertUninitialized = exports.next = exports.AbstractCursor = exports.CURSOR_FLAGS = void 0;
|
||||
const stream_1 = require("stream");
|
||||
const util_1 = require("util");
|
||||
const bson_1 = require("../bson");
|
||||
const error_1 = require("../error");
|
||||
const mongo_types_1 = require("../mongo_types");
|
||||
const execute_operation_1 = require("../operations/execute_operation");
|
||||
const get_more_1 = require("../operations/get_more");
|
||||
const kill_cursors_1 = require("../operations/kill_cursors");
|
||||
const read_concern_1 = require("../read_concern");
|
||||
const read_preference_1 = require("../read_preference");
|
||||
const sessions_1 = require("../sessions");
|
||||
const utils_1 = require("../utils");
|
||||
/** @internal */
|
||||
const kId = Symbol('id');
|
||||
/** @internal */
|
||||
const kDocuments = Symbol('documents');
|
||||
/** @internal */
|
||||
const kServer = Symbol('server');
|
||||
/** @internal */
|
||||
const kNamespace = Symbol('namespace');
|
||||
/** @internal */
|
||||
const kClient = Symbol('client');
|
||||
/** @internal */
|
||||
const kSession = Symbol('session');
|
||||
/** @internal */
|
||||
const kOptions = Symbol('options');
|
||||
/** @internal */
|
||||
const kTransform = Symbol('transform');
|
||||
/** @internal */
|
||||
const kInitialized = Symbol('initialized');
|
||||
/** @internal */
|
||||
const kClosed = Symbol('closed');
|
||||
/** @internal */
|
||||
const kKilled = Symbol('killed');
|
||||
/** @internal */
|
||||
const kInit = Symbol('kInit');
|
||||
/** @public */
|
||||
exports.CURSOR_FLAGS = [
|
||||
'tailable',
|
||||
'oplogReplay',
|
||||
'noCursorTimeout',
|
||||
'awaitData',
|
||||
'exhaust',
|
||||
'partial'
|
||||
];
|
||||
/** @public */
|
||||
class AbstractCursor extends mongo_types_1.TypedEventEmitter {
|
||||
/** @internal */
|
||||
constructor(client, namespace, options = {}) {
|
||||
super();
|
||||
if (!client.s.isMongoClient) {
|
||||
throw new error_1.MongoRuntimeError('Cursor must be constructed with MongoClient');
|
||||
}
|
||||
this[kClient] = client;
|
||||
this[kNamespace] = namespace;
|
||||
this[kId] = null;
|
||||
this[kDocuments] = new utils_1.List();
|
||||
this[kInitialized] = false;
|
||||
this[kClosed] = false;
|
||||
this[kKilled] = false;
|
||||
this[kOptions] = {
|
||||
readPreference: options.readPreference && options.readPreference instanceof read_preference_1.ReadPreference
|
||||
? options.readPreference
|
||||
: read_preference_1.ReadPreference.primary,
|
||||
...(0, bson_1.pluckBSONSerializeOptions)(options)
|
||||
};
|
||||
const readConcern = read_concern_1.ReadConcern.fromOptions(options);
|
||||
if (readConcern) {
|
||||
this[kOptions].readConcern = readConcern;
|
||||
}
|
||||
if (typeof options.batchSize === 'number') {
|
||||
this[kOptions].batchSize = options.batchSize;
|
||||
}
|
||||
// we check for undefined specifically here to allow falsy values
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
if (options.comment !== undefined) {
|
||||
this[kOptions].comment = options.comment;
|
||||
}
|
||||
if (typeof options.maxTimeMS === 'number') {
|
||||
this[kOptions].maxTimeMS = options.maxTimeMS;
|
||||
}
|
||||
if (typeof options.maxAwaitTimeMS === 'number') {
|
||||
this[kOptions].maxAwaitTimeMS = options.maxAwaitTimeMS;
|
||||
}
|
||||
if (options.session instanceof sessions_1.ClientSession) {
|
||||
this[kSession] = options.session;
|
||||
}
|
||||
else {
|
||||
this[kSession] = this[kClient].startSession({ owner: this, explicit: false });
|
||||
}
|
||||
}
|
||||
get id() {
|
||||
return this[kId] ?? undefined;
|
||||
}
|
||||
/** @internal */
|
||||
get client() {
|
||||
return this[kClient];
|
||||
}
|
||||
/** @internal */
|
||||
get server() {
|
||||
return this[kServer];
|
||||
}
|
||||
get namespace() {
|
||||
return this[kNamespace];
|
||||
}
|
||||
get readPreference() {
|
||||
return this[kOptions].readPreference;
|
||||
}
|
||||
get readConcern() {
|
||||
return this[kOptions].readConcern;
|
||||
}
|
||||
/** @internal */
|
||||
get session() {
|
||||
return this[kSession];
|
||||
}
|
||||
set session(clientSession) {
|
||||
this[kSession] = clientSession;
|
||||
}
|
||||
/** @internal */
|
||||
get cursorOptions() {
|
||||
return this[kOptions];
|
||||
}
|
||||
get closed() {
|
||||
return this[kClosed];
|
||||
}
|
||||
get killed() {
|
||||
return this[kKilled];
|
||||
}
|
||||
get loadBalanced() {
|
||||
return !!this[kClient].topology?.loadBalanced;
|
||||
}
|
||||
/** Returns current buffered documents length */
|
||||
bufferedCount() {
|
||||
return this[kDocuments].length;
|
||||
}
|
||||
/** Returns current buffered documents */
|
||||
readBufferedDocuments(number) {
|
||||
const bufferedDocs = [];
|
||||
const documentsToRead = Math.min(number ?? this[kDocuments].length, this[kDocuments].length);
|
||||
for (let count = 0; count < documentsToRead; count++) {
|
||||
const document = this[kDocuments].shift();
|
||||
if (document != null) {
|
||||
bufferedDocs.push(document);
|
||||
}
|
||||
}
|
||||
return bufferedDocs;
|
||||
}
|
||||
async *[Symbol.asyncIterator]() {
|
||||
if (this.closed) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
while (true) {
|
||||
const document = await this.next();
|
||||
// Intentional strict null check, because users can map cursors to falsey values.
|
||||
// We allow mapping to all values except for null.
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
if (document === null) {
|
||||
if (!this.closed) {
|
||||
const message = 'Cursor returned a `null` document, but the cursor is not exhausted. Mapping documents to `null` is not supported in the cursor transform.';
|
||||
await cleanupCursorAsync(this, { needsToEmitClosed: true }).catch(() => null);
|
||||
throw new error_1.MongoAPIError(message);
|
||||
}
|
||||
break;
|
||||
}
|
||||
yield document;
|
||||
if (this[kId] === bson_1.Long.ZERO) {
|
||||
// Cursor exhausted
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
// Only close the cursor if it has not already been closed. This finally clause handles
|
||||
// the case when a user would break out of a for await of loop early.
|
||||
if (!this.closed) {
|
||||
await this.close().catch(() => null);
|
||||
}
|
||||
}
|
||||
}
|
||||
stream(options) {
|
||||
if (options?.transform) {
|
||||
const transform = options.transform;
|
||||
const readable = new ReadableCursorStream(this);
|
||||
return readable.pipe(new stream_1.Transform({
|
||||
objectMode: true,
|
||||
highWaterMark: 1,
|
||||
transform(chunk, _, callback) {
|
||||
try {
|
||||
const transformed = transform(chunk);
|
||||
callback(undefined, transformed);
|
||||
}
|
||||
catch (err) {
|
||||
callback(err);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
return new ReadableCursorStream(this);
|
||||
}
|
||||
async hasNext() {
|
||||
if (this[kId] === bson_1.Long.ZERO) {
|
||||
return false;
|
||||
}
|
||||
if (this[kDocuments].length !== 0) {
|
||||
return true;
|
||||
}
|
||||
const doc = await nextAsync(this, true);
|
||||
if (doc) {
|
||||
this[kDocuments].unshift(doc);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/** Get the next available document from the cursor, returns null if no more documents are available. */
|
||||
async next() {
|
||||
if (this[kId] === bson_1.Long.ZERO) {
|
||||
throw new error_1.MongoCursorExhaustedError();
|
||||
}
|
||||
return nextAsync(this, true);
|
||||
}
|
||||
/**
|
||||
* Try to get the next available document from the cursor or `null` if an empty batch is returned
|
||||
*/
|
||||
async tryNext() {
|
||||
if (this[kId] === bson_1.Long.ZERO) {
|
||||
throw new error_1.MongoCursorExhaustedError();
|
||||
}
|
||||
return nextAsync(this, false);
|
||||
}
|
||||
/**
|
||||
* Iterates over all the documents for this cursor using the iterator, callback pattern.
|
||||
*
|
||||
* If the iterator returns `false`, iteration will stop.
|
||||
*
|
||||
* @param iterator - The iteration callback.
|
||||
* @deprecated - Will be removed in a future release. Use for await...of instead.
|
||||
*/
|
||||
async forEach(iterator) {
|
||||
if (typeof iterator !== 'function') {
|
||||
throw new error_1.MongoInvalidArgumentError('Argument "iterator" must be a function');
|
||||
}
|
||||
for await (const document of this) {
|
||||
const result = iterator(document);
|
||||
if (result === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
async close() {
|
||||
const needsToEmitClosed = !this[kClosed];
|
||||
this[kClosed] = true;
|
||||
await cleanupCursorAsync(this, { needsToEmitClosed });
|
||||
}
|
||||
/**
|
||||
* Returns an array of documents. The caller is responsible for making sure that there
|
||||
* is enough memory to store the results. Note that the array only contains partial
|
||||
* results when this cursor had been previously accessed. In that case,
|
||||
* cursor.rewind() can be used to reset the cursor.
|
||||
*/
|
||||
async toArray() {
|
||||
const array = [];
|
||||
for await (const document of this) {
|
||||
array.push(document);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
/**
|
||||
* Add a cursor flag to the cursor
|
||||
*
|
||||
* @param flag - The flag to set, must be one of following ['tailable', 'oplogReplay', 'noCursorTimeout', 'awaitData', 'partial' -.
|
||||
* @param value - The flag boolean value.
|
||||
*/
|
||||
addCursorFlag(flag, value) {
|
||||
assertUninitialized(this);
|
||||
if (!exports.CURSOR_FLAGS.includes(flag)) {
|
||||
throw new error_1.MongoInvalidArgumentError(`Flag ${flag} is not one of ${exports.CURSOR_FLAGS}`);
|
||||
}
|
||||
if (typeof value !== 'boolean') {
|
||||
throw new error_1.MongoInvalidArgumentError(`Flag ${flag} must be a boolean value`);
|
||||
}
|
||||
this[kOptions][flag] = value;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Map all documents using the provided function
|
||||
* If there is a transform set on the cursor, that will be called first and the result passed to
|
||||
* this function's transform.
|
||||
*
|
||||
* @remarks
|
||||
*
|
||||
* **Note** Cursors use `null` internally to indicate that there are no more documents in the cursor. Providing a mapping
|
||||
* function that maps values to `null` will result in the cursor closing itself before it has finished iterating
|
||||
* all documents. This will **not** result in a memory leak, just surprising behavior. For example:
|
||||
*
|
||||
* ```typescript
|
||||
* const cursor = collection.find({});
|
||||
* cursor.map(() => null);
|
||||
*
|
||||
* const documents = await cursor.toArray();
|
||||
* // documents is always [], regardless of how many documents are in the collection.
|
||||
* ```
|
||||
*
|
||||
* Other falsey values are allowed:
|
||||
*
|
||||
* ```typescript
|
||||
* const cursor = collection.find({});
|
||||
* cursor.map(() => '');
|
||||
*
|
||||
* const documents = await cursor.toArray();
|
||||
* // documents is now an array of empty strings
|
||||
* ```
|
||||
*
|
||||
* **Note for Typescript Users:** adding a transform changes the return type of the iteration of this cursor,
|
||||
* it **does not** return a new instance of a cursor. This means when calling map,
|
||||
* you should always assign the result to a new variable in order to get a correctly typed cursor variable.
|
||||
* Take note of the following example:
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* const cursor: FindCursor<Document> = coll.find();
|
||||
* const mappedCursor: FindCursor<number> = cursor.map(doc => Object.keys(doc).length);
|
||||
* const keyCounts: number[] = await mappedCursor.toArray(); // cursor.toArray() still returns Document[]
|
||||
* ```
|
||||
* @param transform - The mapping transformation method.
|
||||
*/
|
||||
map(transform) {
|
||||
assertUninitialized(this);
|
||||
const oldTransform = this[kTransform]; // TODO(NODE-3283): Improve transform typing
|
||||
if (oldTransform) {
|
||||
this[kTransform] = doc => {
|
||||
return transform(oldTransform(doc));
|
||||
};
|
||||
}
|
||||
else {
|
||||
this[kTransform] = transform;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the ReadPreference for the cursor.
|
||||
*
|
||||
* @param readPreference - The new read preference for the cursor.
|
||||
*/
|
||||
withReadPreference(readPreference) {
|
||||
assertUninitialized(this);
|
||||
if (readPreference instanceof read_preference_1.ReadPreference) {
|
||||
this[kOptions].readPreference = readPreference;
|
||||
}
|
||||
else if (typeof readPreference === 'string') {
|
||||
this[kOptions].readPreference = read_preference_1.ReadPreference.fromString(readPreference);
|
||||
}
|
||||
else {
|
||||
throw new error_1.MongoInvalidArgumentError(`Invalid read preference: ${readPreference}`);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the ReadPreference for the cursor.
|
||||
*
|
||||
* @param readPreference - The new read preference for the cursor.
|
||||
*/
|
||||
withReadConcern(readConcern) {
|
||||
assertUninitialized(this);
|
||||
const resolvedReadConcern = read_concern_1.ReadConcern.fromOptions({ readConcern });
|
||||
if (resolvedReadConcern) {
|
||||
this[kOptions].readConcern = resolvedReadConcern;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set a maxTimeMS on the cursor query, allowing for hard timeout limits on queries (Only supported on MongoDB 2.6 or higher)
|
||||
*
|
||||
* @param value - Number of milliseconds to wait before aborting the query.
|
||||
*/
|
||||
maxTimeMS(value) {
|
||||
assertUninitialized(this);
|
||||
if (typeof value !== 'number') {
|
||||
throw new error_1.MongoInvalidArgumentError('Argument for maxTimeMS must be a number');
|
||||
}
|
||||
this[kOptions].maxTimeMS = value;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the batch size for the cursor.
|
||||
*
|
||||
* @param value - The number of documents to return per batch. See {@link https://www.mongodb.com/docs/manual/reference/command/find/|find command documentation}.
|
||||
*/
|
||||
batchSize(value) {
|
||||
assertUninitialized(this);
|
||||
if (this[kOptions].tailable) {
|
||||
throw new error_1.MongoTailableCursorError('Tailable cursor does not support batchSize');
|
||||
}
|
||||
if (typeof value !== 'number') {
|
||||
throw new error_1.MongoInvalidArgumentError('Operation "batchSize" requires an integer');
|
||||
}
|
||||
this[kOptions].batchSize = value;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Rewind this cursor to its uninitialized state. Any options that are present on the cursor will
|
||||
* remain in effect. Iterating this cursor will cause new queries to be sent to the server, even
|
||||
* if the resultant data has already been retrieved by this cursor.
|
||||
*/
|
||||
rewind() {
|
||||
if (!this[kInitialized]) {
|
||||
return;
|
||||
}
|
||||
this[kId] = null;
|
||||
this[kDocuments].clear();
|
||||
this[kClosed] = false;
|
||||
this[kKilled] = false;
|
||||
this[kInitialized] = false;
|
||||
const session = this[kSession];
|
||||
if (session) {
|
||||
// We only want to end this session if we created it, and it hasn't ended yet
|
||||
if (session.explicit === false) {
|
||||
if (!session.hasEnded) {
|
||||
session.endSession().catch(() => null);
|
||||
}
|
||||
this[kSession] = this.client.startSession({ owner: this, explicit: false });
|
||||
}
|
||||
}
|
||||
}
|
||||
/** @internal */
|
||||
_getMore(batchSize, callback) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const getMoreOperation = new get_more_1.GetMoreOperation(this[kNamespace], this[kId], this[kServer], {
|
||||
...this[kOptions],
|
||||
session: this[kSession],
|
||||
batchSize
|
||||
});
|
||||
(0, execute_operation_1.executeOperation)(this[kClient], getMoreOperation, callback);
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* This function is exposed for the unified test runner's createChangeStream
|
||||
* operation. We cannot refactor to use the abstract _initialize method without
|
||||
* a significant refactor.
|
||||
*/
|
||||
[kInit](callback) {
|
||||
this._initialize(this[kSession], (error, state) => {
|
||||
if (state) {
|
||||
const response = state.response;
|
||||
this[kServer] = state.server;
|
||||
if (response.cursor) {
|
||||
// TODO(NODE-2674): Preserve int64 sent from MongoDB
|
||||
this[kId] =
|
||||
typeof response.cursor.id === 'number'
|
||||
? bson_1.Long.fromNumber(response.cursor.id)
|
||||
: typeof response.cursor.id === 'bigint'
|
||||
? bson_1.Long.fromBigInt(response.cursor.id)
|
||||
: response.cursor.id;
|
||||
if (response.cursor.ns) {
|
||||
this[kNamespace] = (0, utils_1.ns)(response.cursor.ns);
|
||||
}
|
||||
this[kDocuments].pushMany(response.cursor.firstBatch);
|
||||
}
|
||||
// When server responses return without a cursor document, we close this cursor
|
||||
// and return the raw server response. This is often the case for explain commands
|
||||
// for example
|
||||
if (this[kId] == null) {
|
||||
this[kId] = bson_1.Long.ZERO;
|
||||
// TODO(NODE-3286): ExecutionResult needs to accept a generic parameter
|
||||
this[kDocuments].push(state.response);
|
||||
}
|
||||
}
|
||||
// the cursor is now initialized, even if an error occurred or it is dead
|
||||
this[kInitialized] = true;
|
||||
if (error) {
|
||||
return cleanupCursor(this, { error }, () => callback(error, undefined));
|
||||
}
|
||||
if (cursorIsDead(this)) {
|
||||
return cleanupCursor(this, undefined, () => callback());
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.AbstractCursor = AbstractCursor;
|
||||
/** @event */
|
||||
AbstractCursor.CLOSE = 'close';
|
||||
function nextDocument(cursor) {
|
||||
const doc = cursor[kDocuments].shift();
|
||||
if (doc && cursor[kTransform]) {
|
||||
return cursor[kTransform](doc);
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
const nextAsync = (0, util_1.promisify)(next);
|
||||
/**
|
||||
* @param cursor - the cursor on which to call `next`
|
||||
* @param blocking - a boolean indicating whether or not the cursor should `block` until data
|
||||
* is available. Generally, this flag is set to `false` because if the getMore returns no documents,
|
||||
* the cursor has been exhausted. In certain scenarios (ChangeStreams, tailable await cursors and
|
||||
* `tryNext`, for example) blocking is necessary because a getMore returning no documents does
|
||||
* not indicate the end of the cursor.
|
||||
* @param callback - callback to return the result to the caller
|
||||
* @returns
|
||||
*/
|
||||
function next(cursor, blocking, callback) {
|
||||
const cursorId = cursor[kId];
|
||||
if (cursor.closed) {
|
||||
return callback(undefined, null);
|
||||
}
|
||||
if (cursor[kDocuments].length !== 0) {
|
||||
callback(undefined, nextDocument(cursor));
|
||||
return;
|
||||
}
|
||||
if (cursorId == null) {
|
||||
// All cursors must operate within a session, one must be made implicitly if not explicitly provided
|
||||
cursor[kInit](err => {
|
||||
if (err)
|
||||
return callback(err);
|
||||
return next(cursor, blocking, callback);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (cursorIsDead(cursor)) {
|
||||
return cleanupCursor(cursor, undefined, () => callback(undefined, null));
|
||||
}
|
||||
// otherwise need to call getMore
|
||||
const batchSize = cursor[kOptions].batchSize || 1000;
|
||||
cursor._getMore(batchSize, (error, response) => {
|
||||
if (response) {
|
||||
const cursorId = typeof response.cursor.id === 'number'
|
||||
? bson_1.Long.fromNumber(response.cursor.id)
|
||||
: typeof response.cursor.id === 'bigint'
|
||||
? bson_1.Long.fromBigInt(response.cursor.id)
|
||||
: response.cursor.id;
|
||||
cursor[kDocuments].pushMany(response.cursor.nextBatch);
|
||||
cursor[kId] = cursorId;
|
||||
}
|
||||
if (error || cursorIsDead(cursor)) {
|
||||
return cleanupCursor(cursor, { error }, () => callback(error, nextDocument(cursor)));
|
||||
}
|
||||
if (cursor[kDocuments].length === 0 && blocking === false) {
|
||||
return callback(undefined, null);
|
||||
}
|
||||
next(cursor, blocking, callback);
|
||||
});
|
||||
}
|
||||
exports.next = next;
|
||||
function cursorIsDead(cursor) {
|
||||
const cursorId = cursor[kId];
|
||||
return !!cursorId && cursorId.isZero();
|
||||
}
|
||||
const cleanupCursorAsync = (0, util_1.promisify)(cleanupCursor);
|
||||
function cleanupCursor(cursor, options, callback) {
|
||||
const cursorId = cursor[kId];
|
||||
const cursorNs = cursor[kNamespace];
|
||||
const server = cursor[kServer];
|
||||
const session = cursor[kSession];
|
||||
const error = options?.error;
|
||||
const needsToEmitClosed = options?.needsToEmitClosed ?? cursor[kDocuments].length === 0;
|
||||
if (error) {
|
||||
if (cursor.loadBalanced && error instanceof error_1.MongoNetworkError) {
|
||||
return completeCleanup();
|
||||
}
|
||||
}
|
||||
if (cursorId == null || server == null || cursorId.isZero() || cursorNs == null) {
|
||||
if (needsToEmitClosed) {
|
||||
cursor[kClosed] = true;
|
||||
cursor[kId] = bson_1.Long.ZERO;
|
||||
cursor.emit(AbstractCursor.CLOSE);
|
||||
}
|
||||
if (session) {
|
||||
if (session.owner === cursor) {
|
||||
session.endSession({ error }).finally(() => {
|
||||
callback();
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!session.inTransaction()) {
|
||||
(0, sessions_1.maybeClearPinnedConnection)(session, { error });
|
||||
}
|
||||
}
|
||||
return callback();
|
||||
}
|
||||
function completeCleanup() {
|
||||
if (session) {
|
||||
if (session.owner === cursor) {
|
||||
session.endSession({ error }).finally(() => {
|
||||
cursor.emit(AbstractCursor.CLOSE);
|
||||
callback();
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!session.inTransaction()) {
|
||||
(0, sessions_1.maybeClearPinnedConnection)(session, { error });
|
||||
}
|
||||
}
|
||||
cursor.emit(AbstractCursor.CLOSE);
|
||||
return callback();
|
||||
}
|
||||
cursor[kKilled] = true;
|
||||
if (session.hasEnded) {
|
||||
return completeCleanup();
|
||||
}
|
||||
(0, execute_operation_1.executeOperation)(cursor[kClient], new kill_cursors_1.KillCursorsOperation(cursorId, cursorNs, server, { session }))
|
||||
.catch(() => null)
|
||||
.finally(completeCleanup);
|
||||
}
|
||||
/** @internal */
|
||||
function assertUninitialized(cursor) {
|
||||
if (cursor[kInitialized]) {
|
||||
throw new error_1.MongoCursorInUseError();
|
||||
}
|
||||
}
|
||||
exports.assertUninitialized = assertUninitialized;
|
||||
class ReadableCursorStream extends stream_1.Readable {
|
||||
constructor(cursor) {
|
||||
super({
|
||||
objectMode: true,
|
||||
autoDestroy: false,
|
||||
highWaterMark: 1
|
||||
});
|
||||
this._readInProgress = false;
|
||||
this._cursor = cursor;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
_read(size) {
|
||||
if (!this._readInProgress) {
|
||||
this._readInProgress = true;
|
||||
this._readNext();
|
||||
}
|
||||
}
|
||||
_destroy(error, callback) {
|
||||
this._cursor.close().then(() => callback(error), closeError => callback(closeError));
|
||||
}
|
||||
_readNext() {
|
||||
next(this._cursor, true, (err, result) => {
|
||||
if (err) {
|
||||
// NOTE: This is questionable, but we have a test backing the behavior. It seems the
|
||||
// desired behavior is that a stream ends cleanly when a user explicitly closes
|
||||
// a client during iteration. Alternatively, we could do the "right" thing and
|
||||
// propagate the error message by removing this special case.
|
||||
if (err.message.match(/server is closed/)) {
|
||||
this._cursor.close().catch(() => null);
|
||||
return this.push(null);
|
||||
}
|
||||
// NOTE: This is also perhaps questionable. The rationale here is that these errors tend
|
||||
// to be "operation was interrupted", where a cursor has been closed but there is an
|
||||
// active getMore in-flight. This used to check if the cursor was killed but once
|
||||
// that changed to happen in cleanup legitimate errors would not destroy the
|
||||
// stream. There are change streams test specifically test these cases.
|
||||
if (err.message.match(/operation was interrupted/)) {
|
||||
return this.push(null);
|
||||
}
|
||||
// NOTE: The two above checks on the message of the error will cause a null to be pushed
|
||||
// to the stream, thus closing the stream before the destroy call happens. This means
|
||||
// that either of those error messages on a change stream will not get a proper
|
||||
// 'error' event to be emitted (the error passed to destroy). Change stream resumability
|
||||
// relies on that error event to be emitted to create its new cursor and thus was not
|
||||
// working on 4.4 servers because the error emitted on failover was "interrupted at
|
||||
// shutdown" while on 5.0+ it is "The server is in quiesce mode and will shut down".
|
||||
// See NODE-4475.
|
||||
return this.destroy(err);
|
||||
}
|
||||
if (result == null) {
|
||||
this.push(null);
|
||||
}
|
||||
else if (this.destroyed) {
|
||||
this._cursor.close().catch(() => null);
|
||||
}
|
||||
else {
|
||||
if (this.push(result)) {
|
||||
return this._readNext();
|
||||
}
|
||||
this._readInProgress = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=abstract_cursor.js.map
|
1
node_modules/mongodb/lib/cursor/abstract_cursor.js.map
generated
vendored
Normal file
1
node_modules/mongodb/lib/cursor/abstract_cursor.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
168
node_modules/mongodb/lib/cursor/aggregation_cursor.js
generated
vendored
Normal file
168
node_modules/mongodb/lib/cursor/aggregation_cursor.js
generated
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AggregationCursor = void 0;
|
||||
const aggregate_1 = require("../operations/aggregate");
|
||||
const execute_operation_1 = require("../operations/execute_operation");
|
||||
const utils_1 = require("../utils");
|
||||
const abstract_cursor_1 = require("./abstract_cursor");
|
||||
/** @internal */
|
||||
const kPipeline = Symbol('pipeline');
|
||||
/** @internal */
|
||||
const kOptions = Symbol('options');
|
||||
/**
|
||||
* The **AggregationCursor** class is an internal class that embodies an aggregation cursor on MongoDB
|
||||
* allowing for iteration over the results returned from the underlying query. It supports
|
||||
* one by one document iteration, conversion to an array or can be iterated as a Node 4.X
|
||||
* or higher stream
|
||||
* @public
|
||||
*/
|
||||
class AggregationCursor extends abstract_cursor_1.AbstractCursor {
|
||||
/** @internal */
|
||||
constructor(client, namespace, pipeline = [], options = {}) {
|
||||
super(client, namespace, options);
|
||||
this[kPipeline] = pipeline;
|
||||
this[kOptions] = options;
|
||||
}
|
||||
get pipeline() {
|
||||
return this[kPipeline];
|
||||
}
|
||||
clone() {
|
||||
const clonedOptions = (0, utils_1.mergeOptions)({}, this[kOptions]);
|
||||
delete clonedOptions.session;
|
||||
return new AggregationCursor(this.client, this.namespace, this[kPipeline], {
|
||||
...clonedOptions
|
||||
});
|
||||
}
|
||||
map(transform) {
|
||||
return super.map(transform);
|
||||
}
|
||||
/** @internal */
|
||||
_initialize(session, callback) {
|
||||
const aggregateOperation = new aggregate_1.AggregateOperation(this.namespace, this[kPipeline], {
|
||||
...this[kOptions],
|
||||
...this.cursorOptions,
|
||||
session
|
||||
});
|
||||
(0, execute_operation_1.executeOperation)(this.client, aggregateOperation, (err, response) => {
|
||||
if (err || response == null)
|
||||
return callback(err);
|
||||
// TODO: NODE-2882
|
||||
callback(undefined, { server: aggregateOperation.server, session, response });
|
||||
});
|
||||
}
|
||||
/** Execute the explain for the cursor */
|
||||
async explain(verbosity) {
|
||||
return (0, execute_operation_1.executeOperation)(this.client, new aggregate_1.AggregateOperation(this.namespace, this[kPipeline], {
|
||||
...this[kOptions],
|
||||
...this.cursorOptions,
|
||||
explain: verbosity ?? true
|
||||
}));
|
||||
}
|
||||
group($group) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kPipeline].push({ $group });
|
||||
return this;
|
||||
}
|
||||
/** Add a limit stage to the aggregation pipeline */
|
||||
limit($limit) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kPipeline].push({ $limit });
|
||||
return this;
|
||||
}
|
||||
/** Add a match stage to the aggregation pipeline */
|
||||
match($match) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kPipeline].push({ $match });
|
||||
return this;
|
||||
}
|
||||
/** Add an out stage to the aggregation pipeline */
|
||||
out($out) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kPipeline].push({ $out });
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Add a project stage to the aggregation pipeline
|
||||
*
|
||||
* @remarks
|
||||
* In order to strictly type this function you must provide an interface
|
||||
* that represents the effect of your projection on the result documents.
|
||||
*
|
||||
* By default chaining a projection to your cursor changes the returned type to the generic {@link Document} type.
|
||||
* You should specify a parameterized type to have assertions on your final results.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Best way
|
||||
* const docs: AggregationCursor<{ a: number }> = cursor.project<{ a: number }>({ _id: 0, a: true });
|
||||
* // Flexible way
|
||||
* const docs: AggregationCursor<Document> = cursor.project({ _id: 0, a: true });
|
||||
* ```
|
||||
*
|
||||
* @remarks
|
||||
* In order to strictly type this function you must provide an interface
|
||||
* that represents the effect of your projection on the result documents.
|
||||
*
|
||||
* **Note for Typescript Users:** adding a transform changes the return type of the iteration of this cursor,
|
||||
* it **does not** return a new instance of a cursor. This means when calling project,
|
||||
* you should always assign the result to a new variable in order to get a correctly typed cursor variable.
|
||||
* Take note of the following example:
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* const cursor: AggregationCursor<{ a: number; b: string }> = coll.aggregate([]);
|
||||
* const projectCursor = cursor.project<{ a: number }>({ _id: 0, a: true });
|
||||
* const aPropOnlyArray: {a: number}[] = await projectCursor.toArray();
|
||||
*
|
||||
* // or always use chaining and save the final cursor
|
||||
*
|
||||
* const cursor = coll.aggregate().project<{ a: string }>({
|
||||
* _id: 0,
|
||||
* a: { $convert: { input: '$a', to: 'string' }
|
||||
* }});
|
||||
* ```
|
||||
*/
|
||||
project($project) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kPipeline].push({ $project });
|
||||
return this;
|
||||
}
|
||||
/** Add a lookup stage to the aggregation pipeline */
|
||||
lookup($lookup) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kPipeline].push({ $lookup });
|
||||
return this;
|
||||
}
|
||||
/** Add a redact stage to the aggregation pipeline */
|
||||
redact($redact) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kPipeline].push({ $redact });
|
||||
return this;
|
||||
}
|
||||
/** Add a skip stage to the aggregation pipeline */
|
||||
skip($skip) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kPipeline].push({ $skip });
|
||||
return this;
|
||||
}
|
||||
/** Add a sort stage to the aggregation pipeline */
|
||||
sort($sort) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kPipeline].push({ $sort });
|
||||
return this;
|
||||
}
|
||||
/** Add a unwind stage to the aggregation pipeline */
|
||||
unwind($unwind) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kPipeline].push({ $unwind });
|
||||
return this;
|
||||
}
|
||||
/** Add a geoNear stage to the aggregation pipeline */
|
||||
geoNear($geoNear) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kPipeline].push({ $geoNear });
|
||||
return this;
|
||||
}
|
||||
}
|
||||
exports.AggregationCursor = AggregationCursor;
|
||||
//# sourceMappingURL=aggregation_cursor.js.map
|
1
node_modules/mongodb/lib/cursor/aggregation_cursor.js.map
generated
vendored
Normal file
1
node_modules/mongodb/lib/cursor/aggregation_cursor.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"aggregation_cursor.js","sourceRoot":"","sources":["../../src/cursor/aggregation_cursor.ts"],"names":[],"mappings":";;;AAGA,uDAA+E;AAC/E,uEAAoF;AAIpF,oCAAwC;AAExC,uDAAwE;AAKxE,gBAAgB;AAChB,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAC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C,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,sDAAsD;IACtD,OAAO,CAAC,QAAkB;QACxB,IAAA,qCAAmB,EAAC,IAAI,CAAC,CAAC;QAC1B,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AApLD,8CAoLC"}
|
115
node_modules/mongodb/lib/cursor/change_stream_cursor.js
generated
vendored
Normal file
115
node_modules/mongodb/lib/cursor/change_stream_cursor.js
generated
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ChangeStreamCursor = void 0;
|
||||
const change_stream_1 = require("../change_stream");
|
||||
const constants_1 = require("../constants");
|
||||
const aggregate_1 = require("../operations/aggregate");
|
||||
const execute_operation_1 = require("../operations/execute_operation");
|
||||
const utils_1 = require("../utils");
|
||||
const abstract_cursor_1 = require("./abstract_cursor");
|
||||
/** @internal */
|
||||
class ChangeStreamCursor extends abstract_cursor_1.AbstractCursor {
|
||||
constructor(client, namespace, pipeline = [], options = {}) {
|
||||
super(client, namespace, options);
|
||||
this.pipeline = pipeline;
|
||||
this.options = options;
|
||||
this._resumeToken = null;
|
||||
this.startAtOperationTime = options.startAtOperationTime;
|
||||
if (options.startAfter) {
|
||||
this.resumeToken = options.startAfter;
|
||||
}
|
||||
else if (options.resumeAfter) {
|
||||
this.resumeToken = options.resumeAfter;
|
||||
}
|
||||
}
|
||||
set resumeToken(token) {
|
||||
this._resumeToken = token;
|
||||
this.emit(change_stream_1.ChangeStream.RESUME_TOKEN_CHANGED, token);
|
||||
}
|
||||
get resumeToken() {
|
||||
return this._resumeToken;
|
||||
}
|
||||
get resumeOptions() {
|
||||
const options = {
|
||||
...this.options
|
||||
};
|
||||
for (const key of ['resumeAfter', 'startAfter', 'startAtOperationTime']) {
|
||||
delete options[key];
|
||||
}
|
||||
if (this.resumeToken != null) {
|
||||
if (this.options.startAfter && !this.hasReceived) {
|
||||
options.startAfter = this.resumeToken;
|
||||
}
|
||||
else {
|
||||
options.resumeAfter = this.resumeToken;
|
||||
}
|
||||
}
|
||||
else if (this.startAtOperationTime != null && (0, utils_1.maxWireVersion)(this.server) >= 7) {
|
||||
options.startAtOperationTime = this.startAtOperationTime;
|
||||
}
|
||||
return options;
|
||||
}
|
||||
cacheResumeToken(resumeToken) {
|
||||
if (this.bufferedCount() === 0 && this.postBatchResumeToken) {
|
||||
this.resumeToken = this.postBatchResumeToken;
|
||||
}
|
||||
else {
|
||||
this.resumeToken = resumeToken;
|
||||
}
|
||||
this.hasReceived = true;
|
||||
}
|
||||
_processBatch(response) {
|
||||
const cursor = response.cursor;
|
||||
if (cursor.postBatchResumeToken) {
|
||||
this.postBatchResumeToken = response.cursor.postBatchResumeToken;
|
||||
const batch = 'firstBatch' in response.cursor ? response.cursor.firstBatch : response.cursor.nextBatch;
|
||||
if (batch.length === 0) {
|
||||
this.resumeToken = cursor.postBatchResumeToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
clone() {
|
||||
return new ChangeStreamCursor(this.client, this.namespace, this.pipeline, {
|
||||
...this.cursorOptions
|
||||
});
|
||||
}
|
||||
_initialize(session, callback) {
|
||||
const aggregateOperation = new aggregate_1.AggregateOperation(this.namespace, this.pipeline, {
|
||||
...this.cursorOptions,
|
||||
...this.options,
|
||||
session
|
||||
});
|
||||
(0, execute_operation_1.executeOperation)(session.client, aggregateOperation, (err, response) => {
|
||||
if (err || response == null) {
|
||||
return callback(err);
|
||||
}
|
||||
const server = aggregateOperation.server;
|
||||
this.maxWireVersion = (0, utils_1.maxWireVersion)(server);
|
||||
if (this.startAtOperationTime == null &&
|
||||
this.resumeAfter == null &&
|
||||
this.startAfter == null &&
|
||||
this.maxWireVersion >= 7) {
|
||||
this.startAtOperationTime = response.operationTime;
|
||||
}
|
||||
this._processBatch(response);
|
||||
this.emit(constants_1.INIT, response);
|
||||
this.emit(constants_1.RESPONSE);
|
||||
// TODO: NODE-2882
|
||||
callback(undefined, { server, session, response });
|
||||
});
|
||||
}
|
||||
_getMore(batchSize, callback) {
|
||||
super._getMore(batchSize, (err, response) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
this.maxWireVersion = (0, utils_1.maxWireVersion)(this.server);
|
||||
this._processBatch(response);
|
||||
this.emit(change_stream_1.ChangeStream.MORE, response);
|
||||
this.emit(change_stream_1.ChangeStream.RESPONSE);
|
||||
callback(err, response);
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.ChangeStreamCursor = ChangeStreamCursor;
|
||||
//# sourceMappingURL=change_stream_cursor.js.map
|
1
node_modules/mongodb/lib/cursor/change_stream_cursor.js.map
generated
vendored
Normal file
1
node_modules/mongodb/lib/cursor/change_stream_cursor.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"change_stream_cursor.js","sourceRoot":"","sources":["../../src/cursor/change_stream_cursor.ts"],"names":[],"mappings":";;;AACA,oDAM0B;AAC1B,4CAA8C;AAG9C,uDAA6D;AAE7D,uEAAyF;AAEzF,oCAAgF;AAChF,uDAA+E;AAwB/E,gBAAgB;AAChB,MAAa,kBAGX,SAAQ,gCAA2C;IAkBnD,YACE,MAAmB,EACnB,SAA2B,EAC3B,WAAuB,EAAE,EACzB,UAAqC,EAAE;QAEvC,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAElC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC;QAEzD,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;SAC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 +1,381 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FindCursor = exports.FLAGS = void 0;
|
||||
const error_1 = require("../error");
|
||||
const count_1 = require("../operations/count");
|
||||
const execute_operation_1 = require("../operations/execute_operation");
|
||||
const find_1 = require("../operations/find");
|
||||
const sort_1 = require("../sort");
|
||||
const utils_1 = require("../utils");
|
||||
const abstract_cursor_1 = require("./abstract_cursor");
|
||||
/** @internal */
|
||||
const kFilter = Symbol('filter');
|
||||
/** @internal */
|
||||
const kNumReturned = Symbol('numReturned');
|
||||
/** @internal */
|
||||
const kBuiltOptions = Symbol('builtOptions');
|
||||
/** @public Flags allowed for cursor */
|
||||
exports.FLAGS = [
|
||||
'tailable',
|
||||
'oplogReplay',
|
||||
'noCursorTimeout',
|
||||
'awaitData',
|
||||
'exhaust',
|
||||
'partial'
|
||||
];
|
||||
/** @public */
|
||||
class FindCursor extends abstract_cursor_1.AbstractCursor {
|
||||
/** @internal */
|
||||
constructor(client, namespace, filter = {}, options = {}) {
|
||||
super(client, namespace, options);
|
||||
this[kFilter] = filter;
|
||||
this[kBuiltOptions] = options;
|
||||
if (options.sort != null) {
|
||||
this[kBuiltOptions].sort = (0, sort_1.formatSort)(options.sort);
|
||||
}
|
||||
}
|
||||
clone() {
|
||||
const clonedOptions = (0, utils_1.mergeOptions)({}, this[kBuiltOptions]);
|
||||
delete clonedOptions.session;
|
||||
return new FindCursor(this.client, this.namespace, this[kFilter], {
|
||||
...clonedOptions
|
||||
});
|
||||
}
|
||||
map(transform) {
|
||||
return super.map(transform);
|
||||
}
|
||||
/** @internal */
|
||||
_initialize(session, callback) {
|
||||
const findOperation = new find_1.FindOperation(undefined, this.namespace, this[kFilter], {
|
||||
...this[kBuiltOptions],
|
||||
...this.cursorOptions,
|
||||
session
|
||||
});
|
||||
(0, execute_operation_1.executeOperation)(this.client, findOperation, (err, response) => {
|
||||
if (err || response == null)
|
||||
return callback(err);
|
||||
// TODO: We only need this for legacy queries that do not support `limit`, maybe
|
||||
// the value should only be saved in those cases.
|
||||
if (response.cursor) {
|
||||
this[kNumReturned] = response.cursor.firstBatch.length;
|
||||
}
|
||||
else {
|
||||
this[kNumReturned] = response.documents ? response.documents.length : 0;
|
||||
}
|
||||
// TODO: NODE-2882
|
||||
callback(undefined, { server: findOperation.server, session, response });
|
||||
});
|
||||
}
|
||||
/** @internal */
|
||||
_getMore(batchSize, callback) {
|
||||
// NOTE: this is to support client provided limits in pre-command servers
|
||||
const numReturned = this[kNumReturned];
|
||||
if (numReturned) {
|
||||
const limit = this[kBuiltOptions].limit;
|
||||
batchSize =
|
||||
limit && limit > 0 && numReturned + batchSize > limit ? limit - numReturned : batchSize;
|
||||
if (batchSize <= 0) {
|
||||
this.close().finally(() => callback());
|
||||
return;
|
||||
}
|
||||
}
|
||||
super._getMore(batchSize, (err, response) => {
|
||||
if (err)
|
||||
return callback(err);
|
||||
// TODO: wrap this in some logic to prevent it from happening if we don't need this support
|
||||
if (response) {
|
||||
this[kNumReturned] = this[kNumReturned] + response.cursor.nextBatch.length;
|
||||
}
|
||||
callback(undefined, response);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get the count of documents for this cursor
|
||||
* @deprecated Use `collection.estimatedDocumentCount` or `collection.countDocuments` instead
|
||||
*/
|
||||
async count(options) {
|
||||
(0, utils_1.emitWarningOnce)('cursor.count is deprecated and will be removed in the next major version, please use `collection.estimatedDocumentCount` or `collection.countDocuments` instead ');
|
||||
if (typeof options === 'boolean') {
|
||||
throw new error_1.MongoInvalidArgumentError('Invalid first parameter to count');
|
||||
}
|
||||
return (0, execute_operation_1.executeOperation)(this.client, new count_1.CountOperation(this.namespace, this[kFilter], {
|
||||
...this[kBuiltOptions],
|
||||
...this.cursorOptions,
|
||||
...options
|
||||
}));
|
||||
}
|
||||
/** Execute the explain for the cursor */
|
||||
async explain(verbosity) {
|
||||
return (0, execute_operation_1.executeOperation)(this.client, new find_1.FindOperation(undefined, this.namespace, this[kFilter], {
|
||||
...this[kBuiltOptions],
|
||||
...this.cursorOptions,
|
||||
explain: verbosity ?? true
|
||||
}));
|
||||
}
|
||||
/** Set the cursor query */
|
||||
filter(filter) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kFilter] = filter;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the cursor hint
|
||||
*
|
||||
* @param hint - If specified, then the query system will only consider plans using the hinted index.
|
||||
*/
|
||||
hint(hint) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kBuiltOptions].hint = hint;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the cursor min
|
||||
*
|
||||
* @param min - Specify a $min value to specify the inclusive lower bound for a specific index in order to constrain the results of find(). The $min specifies the lower bound for all keys of a specific index in order.
|
||||
*/
|
||||
min(min) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kBuiltOptions].min = min;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the cursor max
|
||||
*
|
||||
* @param max - Specify a $max value to specify the exclusive upper bound for a specific index in order to constrain the results of find(). The $max specifies the upper bound for all keys of a specific index in order.
|
||||
*/
|
||||
max(max) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kBuiltOptions].max = max;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the cursor returnKey.
|
||||
* If set to true, modifies the cursor to only return the index field or fields for the results of the query, rather than documents.
|
||||
* If set to true and the query does not use an index to perform the read operation, the returned documents will not contain any fields.
|
||||
*
|
||||
* @param value - the returnKey value.
|
||||
*/
|
||||
returnKey(value) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kBuiltOptions].returnKey = value;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Modifies the output of a query by adding a field $recordId to matching documents. $recordId is the internal key which uniquely identifies a document in a collection.
|
||||
*
|
||||
* @param value - The $showDiskLoc option has now been deprecated and replaced with the showRecordId field. $showDiskLoc will still be accepted for OP_QUERY stye find.
|
||||
*/
|
||||
showRecordId(value) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kBuiltOptions].showRecordId = value;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Add a query modifier to the cursor query
|
||||
*
|
||||
* @param name - The query modifier (must start with $, such as $orderby etc)
|
||||
* @param value - The modifier value.
|
||||
*/
|
||||
addQueryModifier(name, value) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
if (name[0] !== '$') {
|
||||
throw new error_1.MongoInvalidArgumentError(`${name} is not a valid query modifier`);
|
||||
}
|
||||
// Strip of the $
|
||||
const field = name.substr(1);
|
||||
// NOTE: consider some TS magic for this
|
||||
switch (field) {
|
||||
case 'comment':
|
||||
this[kBuiltOptions].comment = value;
|
||||
break;
|
||||
case 'explain':
|
||||
this[kBuiltOptions].explain = value;
|
||||
break;
|
||||
case 'hint':
|
||||
this[kBuiltOptions].hint = value;
|
||||
break;
|
||||
case 'max':
|
||||
this[kBuiltOptions].max = value;
|
||||
break;
|
||||
case 'maxTimeMS':
|
||||
this[kBuiltOptions].maxTimeMS = value;
|
||||
break;
|
||||
case 'min':
|
||||
this[kBuiltOptions].min = value;
|
||||
break;
|
||||
case 'orderby':
|
||||
this[kBuiltOptions].sort = (0, sort_1.formatSort)(value);
|
||||
break;
|
||||
case 'query':
|
||||
this[kFilter] = value;
|
||||
break;
|
||||
case 'returnKey':
|
||||
this[kBuiltOptions].returnKey = value;
|
||||
break;
|
||||
case 'showDiskLoc':
|
||||
this[kBuiltOptions].showRecordId = value;
|
||||
break;
|
||||
default:
|
||||
throw new error_1.MongoInvalidArgumentError(`Invalid query modifier: ${name}`);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Add a comment to the cursor query allowing for tracking the comment in the log.
|
||||
*
|
||||
* @param value - The comment attached to this query.
|
||||
*/
|
||||
comment(value) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kBuiltOptions].comment = value;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set a maxAwaitTimeMS on a tailing cursor query to allow to customize the timeout value for the option awaitData (Only supported on MongoDB 3.2 or higher, ignored otherwise)
|
||||
*
|
||||
* @param value - Number of milliseconds to wait before aborting the tailed query.
|
||||
*/
|
||||
maxAwaitTimeMS(value) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
if (typeof value !== 'number') {
|
||||
throw new error_1.MongoInvalidArgumentError('Argument for maxAwaitTimeMS must be a number');
|
||||
}
|
||||
this[kBuiltOptions].maxAwaitTimeMS = value;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set a maxTimeMS on the cursor query, allowing for hard timeout limits on queries (Only supported on MongoDB 2.6 or higher)
|
||||
*
|
||||
* @param value - Number of milliseconds to wait before aborting the query.
|
||||
*/
|
||||
maxTimeMS(value) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
if (typeof value !== 'number') {
|
||||
throw new error_1.MongoInvalidArgumentError('Argument for maxTimeMS must be a number');
|
||||
}
|
||||
this[kBuiltOptions].maxTimeMS = value;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Add a project stage to the aggregation pipeline
|
||||
*
|
||||
* @remarks
|
||||
* In order to strictly type this function you must provide an interface
|
||||
* that represents the effect of your projection on the result documents.
|
||||
*
|
||||
* By default chaining a projection to your cursor changes the returned type to the generic
|
||||
* {@link Document} type.
|
||||
* You should specify a parameterized type to have assertions on your final results.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Best way
|
||||
* const docs: FindCursor<{ a: number }> = cursor.project<{ a: number }>({ _id: 0, a: true });
|
||||
* // Flexible way
|
||||
* const docs: FindCursor<Document> = cursor.project({ _id: 0, a: true });
|
||||
* ```
|
||||
*
|
||||
* @remarks
|
||||
*
|
||||
* **Note for Typescript Users:** adding a transform changes the return type of the iteration of this cursor,
|
||||
* it **does not** return a new instance of a cursor. This means when calling project,
|
||||
* you should always assign the result to a new variable in order to get a correctly typed cursor variable.
|
||||
* Take note of the following example:
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* const cursor: FindCursor<{ a: number; b: string }> = coll.find();
|
||||
* const projectCursor = cursor.project<{ a: number }>({ _id: 0, a: true });
|
||||
* const aPropOnlyArray: {a: number}[] = await projectCursor.toArray();
|
||||
*
|
||||
* // or always use chaining and save the final cursor
|
||||
*
|
||||
* const cursor = coll.find().project<{ a: string }>({
|
||||
* _id: 0,
|
||||
* a: { $convert: { input: '$a', to: 'string' }
|
||||
* }});
|
||||
* ```
|
||||
*/
|
||||
project(value) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kBuiltOptions].projection = value;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Sets the sort order of the cursor query.
|
||||
*
|
||||
* @param sort - The key or keys set for the sort.
|
||||
* @param direction - The direction of the sorting (1 or -1).
|
||||
*/
|
||||
sort(sort, direction) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
if (this[kBuiltOptions].tailable) {
|
||||
throw new error_1.MongoTailableCursorError('Tailable cursor does not support sorting');
|
||||
}
|
||||
this[kBuiltOptions].sort = (0, sort_1.formatSort)(sort, direction);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Allows disk use for blocking sort operations exceeding 100MB memory. (MongoDB 3.2 or higher)
|
||||
*
|
||||
* @remarks
|
||||
* {@link https://www.mongodb.com/docs/manual/reference/command/find/#find-cmd-allowdiskuse | find command allowDiskUse documentation}
|
||||
*/
|
||||
allowDiskUse(allow = true) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
if (!this[kBuiltOptions].sort) {
|
||||
throw new error_1.MongoInvalidArgumentError('Option "allowDiskUse" requires a sort specification');
|
||||
}
|
||||
// As of 6.0 the default is true. This allows users to get back to the old behavior.
|
||||
if (!allow) {
|
||||
this[kBuiltOptions].allowDiskUse = false;
|
||||
return this;
|
||||
}
|
||||
this[kBuiltOptions].allowDiskUse = true;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the collation options for the cursor.
|
||||
*
|
||||
* @param value - The cursor collation options (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
|
||||
*/
|
||||
collation(value) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
this[kBuiltOptions].collation = value;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the limit for the cursor.
|
||||
*
|
||||
* @param value - The limit for the cursor query.
|
||||
*/
|
||||
limit(value) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
if (this[kBuiltOptions].tailable) {
|
||||
throw new error_1.MongoTailableCursorError('Tailable cursor does not support limit');
|
||||
}
|
||||
if (typeof value !== 'number') {
|
||||
throw new error_1.MongoInvalidArgumentError('Operation "limit" requires an integer');
|
||||
}
|
||||
this[kBuiltOptions].limit = value;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the skip for the cursor.
|
||||
*
|
||||
* @param value - The skip for the cursor query.
|
||||
*/
|
||||
skip(value) {
|
||||
(0, abstract_cursor_1.assertUninitialized)(this);
|
||||
if (this[kBuiltOptions].tailable) {
|
||||
throw new error_1.MongoTailableCursorError('Tailable cursor does not support skip');
|
||||
}
|
||||
if (typeof value !== 'number') {
|
||||
throw new error_1.MongoInvalidArgumentError('Operation "skip" requires an integer');
|
||||
}
|
||||
this[kBuiltOptions].skip = value;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
exports.FindCursor = FindCursor;
|
||||
//# sourceMappingURL=find_cursor.js.map
|
1
node_modules/mongodb/lib/cursor/find_cursor.js.map
generated
vendored
Normal file
1
node_modules/mongodb/lib/cursor/find_cursor.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
37
node_modules/mongodb/lib/cursor/list_collections_cursor.js
generated
vendored
Normal file
37
node_modules/mongodb/lib/cursor/list_collections_cursor.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ListCollectionsCursor = void 0;
|
||||
const execute_operation_1 = require("../operations/execute_operation");
|
||||
const list_collections_1 = require("../operations/list_collections");
|
||||
const abstract_cursor_1 = require("./abstract_cursor");
|
||||
/** @public */
|
||||
class ListCollectionsCursor extends abstract_cursor_1.AbstractCursor {
|
||||
constructor(db, filter, options) {
|
||||
super(db.client, db.s.namespace, options);
|
||||
this.parent = db;
|
||||
this.filter = filter;
|
||||
this.options = options;
|
||||
}
|
||||
clone() {
|
||||
return new ListCollectionsCursor(this.parent, this.filter, {
|
||||
...this.options,
|
||||
...this.cursorOptions
|
||||
});
|
||||
}
|
||||
/** @internal */
|
||||
_initialize(session, callback) {
|
||||
const operation = new list_collections_1.ListCollectionsOperation(this.parent, this.filter, {
|
||||
...this.cursorOptions,
|
||||
...this.options,
|
||||
session
|
||||
});
|
||||
(0, execute_operation_1.executeOperation)(this.parent.client, operation, (err, response) => {
|
||||
if (err || response == null)
|
||||
return callback(err);
|
||||
// TODO: NODE-2882
|
||||
callback(undefined, { server: operation.server, session, response });
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.ListCollectionsCursor = ListCollectionsCursor;
|
||||
//# sourceMappingURL=list_collections_cursor.js.map
|
1
node_modules/mongodb/lib/cursor/list_collections_cursor.js.map
generated
vendored
Normal file
1
node_modules/mongodb/lib/cursor/list_collections_cursor.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"list_collections_cursor.js","sourceRoot":"","sources":["../../src/cursor/list_collections_cursor.ts"],"names":[],"mappings":";;;AAEA,uEAAoF;AACpF,qEAIwC;AAGxC,uDAAmD;AAEnD,cAAc;AACd,MAAa,qBAIX,SAAQ,gCAAiB;IAKzB,YAAY,EAAM,EAAE,MAAgB,EAAE,OAAgC;QACpE,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,qBAAqB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;YACzD,GAAG,IAAI,CAAC,OAAO;YACf,GAAG,IAAI,CAAC,aAAa;SACtB,CAAC,CAAC;IACL,CAAC;IAED,gBAAgB;IAChB,WAAW,CAAC,OAAkC,EAAE,QAAmC;QACjF,MAAM,SAAS,GAAG,IAAI,2CAAwB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;YACvE,GAAG,IAAI,CAAC,aAAa;YACrB,GAAG,IAAI,CAAC,OAAO;YACf,OAAO;SACR,CAAC,CAAC;QAEH,IAAA,oCAAgB,EAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE;YAChE,IAAI,GAAG,IAAI,QAAQ,IAAI,IAAI;gBAAE,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;YAElD,kBAAkB;YAClB,QAAQ,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAtCD,sDAsCC"}
|
36
node_modules/mongodb/lib/cursor/list_indexes_cursor.js
generated
vendored
Normal file
36
node_modules/mongodb/lib/cursor/list_indexes_cursor.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ListIndexesCursor = void 0;
|
||||
const execute_operation_1 = require("../operations/execute_operation");
|
||||
const indexes_1 = require("../operations/indexes");
|
||||
const abstract_cursor_1 = require("./abstract_cursor");
|
||||
/** @public */
|
||||
class ListIndexesCursor extends abstract_cursor_1.AbstractCursor {
|
||||
constructor(collection, options) {
|
||||
super(collection.client, collection.s.namespace, options);
|
||||
this.parent = collection;
|
||||
this.options = options;
|
||||
}
|
||||
clone() {
|
||||
return new ListIndexesCursor(this.parent, {
|
||||
...this.options,
|
||||
...this.cursorOptions
|
||||
});
|
||||
}
|
||||
/** @internal */
|
||||
_initialize(session, callback) {
|
||||
const operation = new indexes_1.ListIndexesOperation(this.parent, {
|
||||
...this.cursorOptions,
|
||||
...this.options,
|
||||
session
|
||||
});
|
||||
(0, execute_operation_1.executeOperation)(this.parent.client, operation, (err, response) => {
|
||||
if (err || response == null)
|
||||
return callback(err);
|
||||
// TODO: NODE-2882
|
||||
callback(undefined, { server: operation.server, session, response });
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.ListIndexesCursor = ListIndexesCursor;
|
||||
//# sourceMappingURL=list_indexes_cursor.js.map
|
1
node_modules/mongodb/lib/cursor/list_indexes_cursor.js.map
generated
vendored
Normal file
1
node_modules/mongodb/lib/cursor/list_indexes_cursor.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"list_indexes_cursor.js","sourceRoot":"","sources":["../../src/cursor/list_indexes_cursor.ts"],"names":[],"mappings":";;;AACA,uEAAoF;AACpF,mDAAiF;AAGjF,uDAAmD;AAEnD,cAAc;AACd,MAAa,iBAAkB,SAAQ,gCAAc;IAInD,YAAY,UAAsB,EAAE,OAA4B;QAC9D,KAAK,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC1D,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,MAAM,EAAE;YACxC,GAAG,IAAI,CAAC,OAAO;YACf,GAAG,IAAI,CAAC,aAAa;SACtB,CAAC,CAAC;IACL,CAAC;IAED,gBAAgB;IAChB,WAAW,CAAC,OAAkC,EAAE,QAAmC;QACjF,MAAM,SAAS,GAAG,IAAI,8BAAoB,CAAC,IAAI,CAAC,MAAM,EAAE;YACtD,GAAG,IAAI,CAAC,aAAa;YACrB,GAAG,IAAI,CAAC,OAAO;YACf,OAAO;SACR,CAAC,CAAC;QAEH,IAAA,oCAAgB,EAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE;YAChE,IAAI,GAAG,IAAI,QAAQ,IAAI,IAAI;gBAAE,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;YAElD,kBAAkB;YAClB,QAAQ,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAhCD,8CAgCC"}
|
14
node_modules/mongodb/lib/cursor/list_search_indexes_cursor.js
generated
vendored
Normal file
14
node_modules/mongodb/lib/cursor/list_search_indexes_cursor.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ListSearchIndexesCursor = void 0;
|
||||
const aggregation_cursor_1 = require("./aggregation_cursor");
|
||||
/** @internal */
|
||||
class ListSearchIndexesCursor extends aggregation_cursor_1.AggregationCursor {
|
||||
/** @internal */
|
||||
constructor({ fullNamespace: ns, client }, name, options = {}) {
|
||||
const pipeline = name == null ? [{ $listSearchIndexes: {} }] : [{ $listSearchIndexes: { name } }];
|
||||
super(client, ns, pipeline, options);
|
||||
}
|
||||
}
|
||||
exports.ListSearchIndexesCursor = ListSearchIndexesCursor;
|
||||
//# sourceMappingURL=list_search_indexes_cursor.js.map
|
1
node_modules/mongodb/lib/cursor/list_search_indexes_cursor.js.map
generated
vendored
Normal file
1
node_modules/mongodb/lib/cursor/list_search_indexes_cursor.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"list_search_indexes_cursor.js","sourceRoot":"","sources":["../../src/cursor/list_search_indexes_cursor.ts"],"names":[],"mappings":";;;AAEA,6DAAyD;AAKzD,gBAAgB;AAChB,MAAa,uBAAwB,SAAQ,sCAAmC;IAC9E,gBAAgB;IAChB,YACE,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,EAAc,EACzC,IAAmB,EACnB,UAAoC,EAAE;QAEtC,MAAM,QAAQ,GACZ,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QACnF,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;CACF;AAXD,0DAWC"}
|
94
node_modules/mongodb/lib/cursor/run_command_cursor.js
generated
vendored
Normal file
94
node_modules/mongodb/lib/cursor/run_command_cursor.js
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RunCommandCursor = void 0;
|
||||
const error_1 = require("../error");
|
||||
const execute_operation_1 = require("../operations/execute_operation");
|
||||
const get_more_1 = require("../operations/get_more");
|
||||
const run_command_1 = require("../operations/run_command");
|
||||
const utils_1 = require("../utils");
|
||||
const abstract_cursor_1 = require("./abstract_cursor");
|
||||
/** @public */
|
||||
class RunCommandCursor extends abstract_cursor_1.AbstractCursor {
|
||||
/**
|
||||
* Controls the `getMore.comment` field
|
||||
* @param comment - any BSON value
|
||||
*/
|
||||
setComment(comment) {
|
||||
this.getMoreOptions.comment = comment;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Controls the `getMore.maxTimeMS` field. Only valid when cursor is tailable await
|
||||
* @param maxTimeMS - the number of milliseconds to wait for new data
|
||||
*/
|
||||
setMaxTimeMS(maxTimeMS) {
|
||||
this.getMoreOptions.maxAwaitTimeMS = maxTimeMS;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Controls the `getMore.batchSize` field
|
||||
* @param maxTimeMS - the number documents to return in the `nextBatch`
|
||||
*/
|
||||
setBatchSize(batchSize) {
|
||||
this.getMoreOptions.batchSize = batchSize;
|
||||
return this;
|
||||
}
|
||||
/** Unsupported for RunCommandCursor */
|
||||
clone() {
|
||||
throw new error_1.MongoAPIError('Clone not supported, create a new cursor with db.runCursorCommand');
|
||||
}
|
||||
/** Unsupported for RunCommandCursor: readConcern must be configured directly on command document */
|
||||
withReadConcern(_) {
|
||||
throw new error_1.MongoAPIError('RunCommandCursor does not support readConcern it must be attached to the command being run');
|
||||
}
|
||||
/** Unsupported for RunCommandCursor: various cursor flags must be configured directly on command document */
|
||||
addCursorFlag(_, __) {
|
||||
throw new error_1.MongoAPIError('RunCommandCursor does not support cursor flags, they must be attached to the command being run');
|
||||
}
|
||||
/** Unsupported for RunCommandCursor: maxTimeMS must be configured directly on command document */
|
||||
maxTimeMS(_) {
|
||||
throw new error_1.MongoAPIError('maxTimeMS must be configured on the command document directly, to configure getMore.maxTimeMS use cursor.setMaxTimeMS()');
|
||||
}
|
||||
/** Unsupported for RunCommandCursor: batchSize must be configured directly on command document */
|
||||
batchSize(_) {
|
||||
throw new error_1.MongoAPIError('batchSize must be configured on the command document directly, to configure getMore.batchSize use cursor.setBatchSize()');
|
||||
}
|
||||
/** @internal */
|
||||
constructor(db, command, options = {}) {
|
||||
super(db.client, (0, utils_1.ns)(db.namespace), options);
|
||||
this.getMoreOptions = {};
|
||||
this.db = db;
|
||||
this.command = Object.freeze({ ...command });
|
||||
}
|
||||
/** @internal */
|
||||
_initialize(session, callback) {
|
||||
const operation = new run_command_1.RunCommandOperation(this.db, this.command, {
|
||||
...this.cursorOptions,
|
||||
session: session,
|
||||
readPreference: this.cursorOptions.readPreference
|
||||
});
|
||||
(0, execute_operation_1.executeOperation)(this.client, operation).then(response => {
|
||||
if (response.cursor == null) {
|
||||
callback(new error_1.MongoUnexpectedServerResponseError('Expected server to respond with cursor'));
|
||||
return;
|
||||
}
|
||||
callback(undefined, {
|
||||
server: operation.server,
|
||||
session,
|
||||
response
|
||||
});
|
||||
}, err => callback(err));
|
||||
}
|
||||
/** @internal */
|
||||
_getMore(_batchSize, callback) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const getMoreOperation = new get_more_1.GetMoreOperation(this.namespace, this.id, this.server, {
|
||||
...this.cursorOptions,
|
||||
session: this.session,
|
||||
...this.getMoreOptions
|
||||
});
|
||||
(0, execute_operation_1.executeOperation)(this.client, getMoreOperation, callback);
|
||||
}
|
||||
}
|
||||
exports.RunCommandCursor = RunCommandCursor;
|
||||
//# sourceMappingURL=run_command_cursor.js.map
|
1
node_modules/mongodb/lib/cursor/run_command_cursor.js.map
generated
vendored
Normal file
1
node_modules/mongodb/lib/cursor/run_command_cursor.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"run_command_cursor.js","sourceRoot":"","sources":["../../src/cursor/run_command_cursor.ts"],"names":[],"mappings":";;;AAEA,oCAA6E;AAC7E,uEAAoF;AACpF,qDAA0D;AAC1D,2DAAgE;AAIhE,oCAAwC;AACxC,uDAAmD;AAcnD,cAAc;AACd,MAAa,gBAAiB,SAAQ,gCAAc;IAQlD;;;OAGG;IACI,UAAU,CAAC,OAAY;QAC5B,IAAI,CAAC,cAAc,CAAC,OAAO,GAAG,OAAO,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,SAAiB;QACnC,IAAI,CAAC,cAAc,CAAC,cAAc,GAAG,SAAS,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,SAAiB;QACnC,IAAI,C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