Skip to content

feat(NODE-6883): allow rawData option on time series collections #4581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/bulk/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,12 @@ export interface BulkWriteOptions extends CommandOperationOptions {

/** @internal */
timeoutContext?: TimeoutContext;
/**
* Used when the command needs to grant access to the underlying namespaces for time series collections.
* Only available on server versions 8.2 and above.
* @public
**/
rawData?: boolean;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/cmap/wire_protocol/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export const MIN_SUPPORTED_SERVER_VERSION = '4.2';
export const MAX_SUPPORTED_SERVER_VERSION = '8.0';
export const MAX_SUPPORTED_SERVER_VERSION = '8.2';
export const MIN_SUPPORTED_WIRE_VERSION = 8;
export const MAX_SUPPORTED_WIRE_VERSION = 25;
export const MAX_SUPPORTED_WIRE_VERSION = 27;
export const MIN_SUPPORTED_QE_WIRE_VERSION = 21;
export const MIN_SUPPORTED_QE_SERVER_VERSION = '7.0';
export const MIN_SUPPORTED_RAW_DATA_WIRE_VERSION = 27;
export const MIN_SUPPORTED_RAW_DATA_SERVER_VERSION = '8.2';
export const OP_REPLY = 1;
export const OP_UPDATE = 2001;
export const OP_INSERT = 2002;
Expand Down
15 changes: 14 additions & 1 deletion src/operations/aggregate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { Document } from '../bson';
import { MIN_SUPPORTED_RAW_DATA_WIRE_VERSION } from '../cmap/wire_protocol/constants';
import { CursorResponse, ExplainedCursorResponse } from '../cmap/wire_protocol/responses';
import { type CursorTimeoutMode } from '../cursor/abstract_cursor';
import { MongoInvalidArgumentError } from '../error';
import { type ExplainOptions } from '../explain';
import type { Server } from '../sdam/server';
import type { ClientSession } from '../sessions';
import { type TimeoutContext } from '../timeout';
import { maxWireVersion, type MongoDBNamespace } from '../utils';
import { decorateRawData, maxWireVersion, type MongoDBNamespace } from '../utils';
import { WriteConcern } from '../write_concern';
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
import { Aspect, defineAspects, type Hint } from './operation';
Expand Down Expand Up @@ -48,6 +49,12 @@ export interface AggregateOptions extends Omit<CommandOperationOptions, 'explain
explain?: ExplainOptions['explain'];
/** @internal */
timeoutMode?: CursorTimeoutMode;
/**
* Used when the command needs to grant access to the underlying namespaces for time series collections.
* Only available on server versions 8.2 and above.
* @public
**/
rawData?: boolean;
}

/** @internal */
Expand Down Expand Up @@ -152,6 +159,12 @@ export class AggregateOperation extends CommandOperation<CursorResponse> {
command.cursor.batchSize = options.batchSize;
}

decorateRawData(command, !!options.rawData, serverWireVersion);

if (options.rawData != null && serverWireVersion >= MIN_SUPPORTED_RAW_DATA_WIRE_VERSION) {
command.rawData = options.rawData;
}

return await super.executeCommand(
server,
session,
Expand Down
6 changes: 5 additions & 1 deletion src/operations/client_bulk_write/client_bulk_write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ClientBulkWriteCursorResponse } from '../../cmap/wire_protocol/response
import type { Server } from '../../sdam/server';
import type { ClientSession } from '../../sessions';
import { type TimeoutContext } from '../../timeout';
import { MongoDBNamespace } from '../../utils';
import { decorateRawData, maxWireVersion, MongoDBNamespace } from '../../utils';
import { CommandOperation } from '../command';
import { Aspect, defineAspects } from '../operation';
import { type ClientBulkWriteCommandBuilder } from './command_builder';
Expand Down Expand Up @@ -47,6 +47,7 @@ export class ClientBulkWriteOperation extends CommandOperation<ClientBulkWriteCu
session: ClientSession | undefined,
timeoutContext: TimeoutContext
): Promise<ClientBulkWriteCursorResponse> {
const serverWireVersion = maxWireVersion(server);
let command;

if (server.description.type === ServerType.LoadBalancer) {
Expand Down Expand Up @@ -95,6 +96,9 @@ export class ClientBulkWriteOperation extends CommandOperation<ClientBulkWriteCu
if (!this.canRetryWrite) {
this.options.willRetryWrite = false;
}

decorateRawData(command, !!this.options.rawData, serverWireVersion);

return await super.executeCommand(
server,
session,
Expand Down
6 changes: 6 additions & 0 deletions src/operations/client_bulk_write/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export interface ClientBulkWriteOptions extends CommandOperationOptions {
* BulkWriteResult.
*/
verboseResults?: boolean;
/**
* Used when the command needs to grant access to the underlying namespaces for time series collections.
* Only available on server versions 8.2 and above.
* @public
**/
rawData?: boolean;
}

/** @public */
Expand Down
11 changes: 10 additions & 1 deletion src/operations/count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Collection } from '../collection';
import type { Server } from '../sdam/server';
import type { ClientSession } from '../sessions';
import { type TimeoutContext } from '../timeout';
import type { MongoDBNamespace } from '../utils';
import { decorateRawData, maxWireVersion, type MongoDBNamespace } from '../utils';
import { CommandOperation, type CommandOperationOptions } from './command';
import { Aspect, defineAspects } from './operation';

Expand All @@ -19,6 +19,12 @@ export interface CountOptions extends CommandOperationOptions {
maxTimeMS?: number;
/** An index name hint for the query. */
hint?: string | Document;
/**
* Used when the command needs to grant access to the underlying namespaces for time series collections.
* Only available on server versions 8.2 and above.
* @public
**/
rawData?: boolean;
}

/** @internal */
Expand All @@ -45,6 +51,7 @@ export class CountOperation extends CommandOperation<number> {
timeoutContext: TimeoutContext
): Promise<number> {
const options = this.options;
const serverWireVersion = maxWireVersion(server);
const cmd: Document = {
count: this.collectionName,
query: this.query
Expand All @@ -66,6 +73,8 @@ export class CountOperation extends CommandOperation<number> {
cmd.maxTimeMS = options.maxTimeMS;
}

decorateRawData(cmd, !!options.rawData, serverWireVersion);

const result = await super.executeCommand(server, session, cmd, timeoutContext);
return result ? result.n : 0;
}
Expand Down
11 changes: 10 additions & 1 deletion src/operations/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { type TODO_NODE_3286 } from '../mongo_types';
import type { Server } from '../sdam/server';
import type { ClientSession } from '../sessions';
import { type TimeoutContext } from '../timeout';
import { type MongoDBNamespace } from '../utils';
import { decorateRawData, maxWireVersion, type MongoDBNamespace } from '../utils';
import { type WriteConcernOptions } from '../write_concern';
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
import { Aspect, defineAspects, type Hint } from './operation';
Expand All @@ -20,6 +20,12 @@ export interface DeleteOptions extends CommandOperationOptions, WriteConcernOpti
hint?: string | Document;
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
let?: Document;
/**
* Used when the command needs to grant access to the underlying namespaces for time series collections.
* Only available on server versions 8.2 and above.
* @public
**/
rawData?: boolean;
}

/** @public */
Expand Down Expand Up @@ -71,6 +77,7 @@ export class DeleteOperation extends CommandOperation<DeleteResult> {
session: ClientSession | undefined,
timeoutContext: TimeoutContext
): Promise<DeleteResult> {
const serverWireVersion = maxWireVersion(server);
const options = this.options ?? {};
const ordered = typeof options.ordered === 'boolean' ? options.ordered : true;
const command: Document = {
Expand All @@ -97,6 +104,8 @@ export class DeleteOperation extends CommandOperation<DeleteResult> {
}
}

decorateRawData(command, !!this.options.rawData, serverWireVersion);

const res: TODO_NODE_3286 = await super.executeCommand(
server,
session,
Expand Down
16 changes: 15 additions & 1 deletion src/operations/distinct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import type { Collection } from '../collection';
import type { Server } from '../sdam/server';
import type { ClientSession } from '../sessions';
import { type TimeoutContext } from '../timeout';
import { decorateWithCollation, decorateWithReadConcern } from '../utils';
import {
decorateRawData,
decorateWithCollation,
decorateWithReadConcern,
maxWireVersion
} from '../utils';
import { CommandOperation, type CommandOperationOptions } from './command';
import { Aspect, defineAspects } from './operation';

Expand All @@ -21,6 +26,12 @@ export type DistinctOptions = CommandOperationOptions & {
* See https://www.mongodb.com/docs/manual/reference/command/distinct/#command-fields.
*/
hint?: Document | string;
/**
* Used when the command needs to grant access to the underlying namespaces for time series collections.
* Only available on server versions 8.2 and above.
* @public
**/
rawData?: boolean;
};

/**
Expand Down Expand Up @@ -61,6 +72,7 @@ export class DistinctOperation extends CommandOperation<any[]> {
session: ClientSession | undefined,
timeoutContext: TimeoutContext
): Promise<any[]> {
const serverWireVersion = maxWireVersion(server);
const coll = this.collection;
const key = this.key;
const query = this.query;
Expand Down Expand Up @@ -94,6 +106,8 @@ export class DistinctOperation extends CommandOperation<any[]> {
// Have we specified collation
decorateWithCollation(cmd, coll, options);

decorateRawData(cmd, !!this.options.rawData, serverWireVersion);

const result = await super.executeCommand(server, session, cmd, timeoutContext);

// @ts-expect-error: Explain always returns a document
Expand Down
10 changes: 10 additions & 0 deletions src/operations/estimated_document_count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Collection } from '../collection';
import type { Server } from '../sdam/server';
import type { ClientSession } from '../sessions';
import { type TimeoutContext } from '../timeout';
import { decorateRawData, maxWireVersion } from '../utils';
import { CommandOperation, type CommandOperationOptions } from './command';
import { Aspect, defineAspects } from './operation';

Expand All @@ -14,6 +15,12 @@ export interface EstimatedDocumentCountOptions extends CommandOperationOptions {
* This option is sent only if the caller explicitly provides a value. The default is to not send a value.
*/
maxTimeMS?: number;
/**
* Used when the command needs to grant access to the underlying namespaces for time series collections.
* Only available on server versions 8.2 and above.
* @public
**/
rawData?: boolean;
}

/** @internal */
Expand All @@ -36,6 +43,7 @@ export class EstimatedDocumentCountOperation extends CommandOperation<number> {
session: ClientSession | undefined,
timeoutContext: TimeoutContext
): Promise<number> {
const serverWireVersion = maxWireVersion(server);
const cmd: Document = { count: this.collectionName };

if (typeof this.options.maxTimeMS === 'number') {
Expand All @@ -48,6 +56,8 @@ export class EstimatedDocumentCountOperation extends CommandOperation<number> {
cmd.comment = this.options.comment;
}

decorateRawData(cmd, !!this.options.rawData, serverWireVersion);

const response = await super.executeCommand(server, session, cmd, timeoutContext);

return response?.n || 0;
Expand Down
15 changes: 14 additions & 1 deletion src/operations/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import type { Server } from '../sdam/server';
import type { ClientSession } from '../sessions';
import { formatSort, type Sort } from '../sort';
import { type TimeoutContext } from '../timeout';
import { type MongoDBNamespace, normalizeHintField } from '../utils';
import {
decorateRawData,
maxWireVersion,
type MongoDBNamespace,
normalizeHintField
} from '../utils';
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
import { Aspect, defineAspects, type Hint } from './operation';

Expand Down Expand Up @@ -79,6 +84,12 @@ export interface FindOptions<TSchema extends Document = Document>
explain?: ExplainOptions['explain'];
/** @internal*/
timeoutMode?: CursorTimeoutMode;
/**
* Used when the command needs to grant access to the underlying namespaces for time series collections.
* Only available on server versions 8.2 and above.
* @public
**/
rawData?: boolean;
}

/** @internal */
Expand Down Expand Up @@ -118,6 +129,7 @@ export class FindOperation extends CommandOperation<CursorResponse> {
timeoutContext: TimeoutContext
): Promise<CursorResponse> {
this.server = server;
const serverWireVersion = maxWireVersion(server);

const options = this.options;

Expand All @@ -126,6 +138,7 @@ export class FindOperation extends CommandOperation<CursorResponse> {
validateExplainTimeoutOptions(this.options, this.explain);
findCommand = decorateWithExplain(findCommand, this.explain);
}
decorateRawData(findCommand, !!this.options.rawData, serverWireVersion);

return await server.command(
this.ns,
Expand Down
27 changes: 26 additions & 1 deletion src/operations/find_and_modify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import type { Server } from '../sdam/server';
import type { ClientSession } from '../sessions';
import { formatSort, type Sort, type SortForCmd } from '../sort';
import { type TimeoutContext } from '../timeout';
import { decorateWithCollation, hasAtomicOperators, maxWireVersion } from '../utils';
import {
decorateRawData,
decorateWithCollation,
hasAtomicOperators,
maxWireVersion
} from '../utils';
import { type WriteConcern, type WriteConcernSettings } from '../write_concern';
import { CommandOperation, type CommandOperationOptions } from './command';
import { Aspect, defineAspects } from './operation';
Expand Down Expand Up @@ -34,6 +39,12 @@ export interface FindOneAndDeleteOptions extends CommandOperationOptions {
* Return the ModifyResult instead of the modified document. Defaults to false
*/
includeResultMetadata?: boolean;
/**
* Used when the command needs to grant access to the underlying namespaces for time series collections.
* Only available on server versions 8.2 and above.
* @public
**/
rawData?: boolean;
}

/** @public */
Expand All @@ -56,6 +67,12 @@ export interface FindOneAndReplaceOptions extends CommandOperationOptions {
* Return the ModifyResult instead of the modified document. Defaults to false
*/
includeResultMetadata?: boolean;
/**
* Used when the command needs to grant access to the underlying namespaces for time series collections.
* Only available on server versions 8.2 and above.
* @public
**/
rawData?: boolean;
}

/** @public */
Expand All @@ -80,6 +97,12 @@ export interface FindOneAndUpdateOptions extends CommandOperationOptions {
* Return the ModifyResult instead of the modified document. Defaults to false
*/
includeResultMetadata?: boolean;
/**
* Used when the command needs to grant access to the underlying namespaces for time series collections.
* Only available on server versions 8.2 and above.
* @public
**/
rawData?: boolean;
}

/** @internal */
Expand Down Expand Up @@ -186,6 +209,7 @@ export class FindAndModifyOperation extends CommandOperation<Document> {
session: ClientSession | undefined,
timeoutContext: TimeoutContext
): Promise<Document> {
const serverWireVersion = maxWireVersion(server);
const coll = this.collection;
const query = this.query;
const options = { ...this.options, ...this.bsonOptions };
Expand All @@ -198,6 +222,7 @@ export class FindAndModifyOperation extends CommandOperation<Document> {
};

decorateWithCollation(cmd, coll, options);
decorateRawData(cmd, !!this.options.rawData, serverWireVersion);

if (options.hint) {
// TODO: once this method becomes a CommandOperation we will have the server
Expand Down
Loading