Skip to content

Commit 6f82b80

Browse files
committed
feat(NODE-6883): allow rawData on time series collections
1 parent af0bb5a commit 6f82b80

File tree

71 files changed

+5503
-14
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+5503
-14
lines changed

src/bulk/common.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,12 @@ export interface BulkWriteOptions extends CommandOperationOptions {
852852

853853
/** @internal */
854854
timeoutContext?: TimeoutContext;
855+
/**
856+
* Used when the command needs to grant access to the underlying namespaces for time series collections.
857+
* Only available on server versions 8.2 and above.
858+
* @public
859+
**/
860+
rawData?: boolean;
855861
}
856862

857863
/**

src/cmap/wire_protocol/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export const MIN_SUPPORTED_WIRE_VERSION = 8;
44
export const MAX_SUPPORTED_WIRE_VERSION = 25;
55
export const MIN_SUPPORTED_QE_WIRE_VERSION = 21;
66
export const MIN_SUPPORTED_QE_SERVER_VERSION = '7.0';
7+
export const MIN_SUPPORTED_RAW_DATA_WIRE_VERSION = 27;
8+
export const MIN_SUPPORTED_RAW_DATA_SERVER_VERSION = '8.2';
79
export const OP_REPLY = 1;
810
export const OP_UPDATE = 2001;
911
export const OP_INSERT = 2002;

src/operations/aggregate.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type { Document } from '../bson';
2+
import { MIN_SUPPORTED_RAW_DATA_WIRE_VERSION } from '../cmap/wire_protocol/constants';
23
import { CursorResponse, ExplainedCursorResponse } from '../cmap/wire_protocol/responses';
34
import { type CursorTimeoutMode } from '../cursor/abstract_cursor';
45
import { MongoInvalidArgumentError } from '../error';
56
import { type ExplainOptions } from '../explain';
67
import type { Server } from '../sdam/server';
78
import type { ClientSession } from '../sessions';
89
import { type TimeoutContext } from '../timeout';
9-
import { maxWireVersion, type MongoDBNamespace } from '../utils';
10+
import { decorateRawData, maxWireVersion, type MongoDBNamespace } from '../utils';
1011
import { WriteConcern } from '../write_concern';
1112
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
1213
import { Aspect, defineAspects, type Hint } from './operation';
@@ -48,6 +49,12 @@ export interface AggregateOptions extends Omit<CommandOperationOptions, 'explain
4849
explain?: ExplainOptions['explain'];
4950
/** @internal */
5051
timeoutMode?: CursorTimeoutMode;
52+
/**
53+
* Used when the command needs to grant access to the underlying namespaces for time series collections.
54+
* Only available on server versions 8.2 and above.
55+
* @public
56+
**/
57+
rawData?: boolean;
5158
}
5259

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

162+
decorateRawData(command, !!options.rawData, serverWireVersion);
163+
164+
if (options.rawData != null && serverWireVersion >= MIN_SUPPORTED_RAW_DATA_WIRE_VERSION) {
165+
command.rawData = options.rawData;
166+
}
167+
155168
return await super.executeCommand(
156169
server,
157170
session,

src/operations/client_bulk_write/client_bulk_write.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ClientBulkWriteCursorResponse } from '../../cmap/wire_protocol/response
33
import type { Server } from '../../sdam/server';
44
import type { ClientSession } from '../../sessions';
55
import { type TimeoutContext } from '../../timeout';
6-
import { MongoDBNamespace } from '../../utils';
6+
import { decorateRawData, maxWireVersion, MongoDBNamespace } from '../../utils';
77
import { CommandOperation } from '../command';
88
import { Aspect, defineAspects } from '../operation';
99
import { type ClientBulkWriteCommandBuilder } from './command_builder';
@@ -47,6 +47,7 @@ export class ClientBulkWriteOperation extends CommandOperation<ClientBulkWriteCu
4747
session: ClientSession | undefined,
4848
timeoutContext: TimeoutContext
4949
): Promise<ClientBulkWriteCursorResponse> {
50+
const serverWireVersion = maxWireVersion(server);
5051
let command;
5152

5253
if (server.description.type === ServerType.LoadBalancer) {
@@ -95,6 +96,9 @@ export class ClientBulkWriteOperation extends CommandOperation<ClientBulkWriteCu
9596
if (!this.canRetryWrite) {
9697
this.options.willRetryWrite = false;
9798
}
99+
100+
decorateRawData(command, !!this.options.rawData, serverWireVersion);
101+
98102
return await super.executeCommand(
99103
server,
100104
session,

src/operations/client_bulk_write/common.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ export interface ClientBulkWriteOptions extends CommandOperationOptions {
2424
* BulkWriteResult.
2525
*/
2626
verboseResults?: boolean;
27+
/**
28+
* Used when the command needs to grant access to the underlying namespaces for time series collections.
29+
* Only available on server versions 8.2 and above.
30+
* @public
31+
**/
32+
rawData?: boolean;
2733
}
2834

2935
/** @public */

src/operations/count.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Collection } from '../collection';
33
import type { Server } from '../sdam/server';
44
import type { ClientSession } from '../sessions';
55
import { type TimeoutContext } from '../timeout';
6-
import type { MongoDBNamespace } from '../utils';
6+
import { decorateRawData, maxWireVersion, type MongoDBNamespace } from '../utils';
77
import { CommandOperation, type CommandOperationOptions } from './command';
88
import { Aspect, defineAspects } from './operation';
99

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

2430
/** @internal */
@@ -45,6 +51,7 @@ export class CountOperation extends CommandOperation<number> {
4551
timeoutContext: TimeoutContext
4652
): Promise<number> {
4753
const options = this.options;
54+
const serverWireVersion = maxWireVersion(server);
4855
const cmd: Document = {
4956
count: this.collectionName,
5057
query: this.query
@@ -66,6 +73,8 @@ export class CountOperation extends CommandOperation<number> {
6673
cmd.maxTimeMS = options.maxTimeMS;
6774
}
6875

76+
decorateRawData(cmd, !!options.rawData, serverWireVersion);
77+
6978
const result = await super.executeCommand(server, session, cmd, timeoutContext);
7079
return result ? result.n : 0;
7180
}

src/operations/delete.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { type TODO_NODE_3286 } from '../mongo_types';
55
import type { Server } from '../sdam/server';
66
import type { ClientSession } from '../sessions';
77
import { type TimeoutContext } from '../timeout';
8-
import { type MongoDBNamespace } from '../utils';
8+
import { decorateRawData, maxWireVersion, type MongoDBNamespace } from '../utils';
99
import { type WriteConcernOptions } from '../write_concern';
1010
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
1111
import { Aspect, defineAspects, type Hint } from './operation';
@@ -20,6 +20,12 @@ export interface DeleteOptions extends CommandOperationOptions, WriteConcernOpti
2020
hint?: string | Document;
2121
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
2222
let?: Document;
23+
/**
24+
* Used when the command needs to grant access to the underlying namespaces for time series collections.
25+
* Only available on server versions 8.2 and above.
26+
* @public
27+
**/
28+
rawData?: boolean;
2329
}
2430

2531
/** @public */
@@ -71,6 +77,7 @@ export class DeleteOperation extends CommandOperation<DeleteResult> {
7177
session: ClientSession | undefined,
7278
timeoutContext: TimeoutContext
7379
): Promise<DeleteResult> {
80+
const serverWireVersion = maxWireVersion(server);
7481
const options = this.options ?? {};
7582
const ordered = typeof options.ordered === 'boolean' ? options.ordered : true;
7683
const command: Document = {
@@ -97,6 +104,8 @@ export class DeleteOperation extends CommandOperation<DeleteResult> {
97104
}
98105
}
99106

107+
decorateRawData(command, !!this.options.rawData, serverWireVersion);
108+
100109
const res: TODO_NODE_3286 = await super.executeCommand(
101110
server,
102111
session,

src/operations/distinct.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import type { Collection } from '../collection';
33
import type { Server } from '../sdam/server';
44
import type { ClientSession } from '../sessions';
55
import { type TimeoutContext } from '../timeout';
6-
import { decorateWithCollation, decorateWithReadConcern } from '../utils';
6+
import {
7+
decorateRawData,
8+
decorateWithCollation,
9+
decorateWithReadConcern,
10+
maxWireVersion
11+
} from '../utils';
712
import { CommandOperation, type CommandOperationOptions } from './command';
813
import { Aspect, defineAspects } from './operation';
914

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

2637
/**
@@ -61,6 +72,7 @@ export class DistinctOperation extends CommandOperation<any[]> {
6172
session: ClientSession | undefined,
6273
timeoutContext: TimeoutContext
6374
): Promise<any[]> {
75+
const serverWireVersion = maxWireVersion(server);
6476
const coll = this.collection;
6577
const key = this.key;
6678
const query = this.query;
@@ -94,6 +106,8 @@ export class DistinctOperation extends CommandOperation<any[]> {
94106
// Have we specified collation
95107
decorateWithCollation(cmd, coll, options);
96108

109+
decorateRawData(cmd, !!this.options.rawData, serverWireVersion);
110+
97111
const result = await super.executeCommand(server, session, cmd, timeoutContext);
98112

99113
// @ts-expect-error: Explain always returns a document

src/operations/estimated_document_count.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Collection } from '../collection';
33
import type { Server } from '../sdam/server';
44
import type { ClientSession } from '../sessions';
55
import { type TimeoutContext } from '../timeout';
6+
import { decorateRawData, maxWireVersion } from '../utils';
67
import { CommandOperation, type CommandOperationOptions } from './command';
78
import { Aspect, defineAspects } from './operation';
89

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

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

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

59+
decorateRawData(cmd, !!this.options.rawData, serverWireVersion);
60+
5161
const response = await super.executeCommand(server, session, cmd, timeoutContext);
5262

5363
return response?.n || 0;

src/operations/find.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ import type { Server } from '../sdam/server';
1212
import type { ClientSession } from '../sessions';
1313
import { formatSort, type Sort } from '../sort';
1414
import { type TimeoutContext } from '../timeout';
15-
import { type MongoDBNamespace, normalizeHintField } from '../utils';
15+
import {
16+
decorateRawData,
17+
maxWireVersion,
18+
type MongoDBNamespace,
19+
normalizeHintField
20+
} from '../utils';
1621
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
1722
import { Aspect, defineAspects, type Hint } from './operation';
1823

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

8495
/** @internal */
@@ -118,6 +129,7 @@ export class FindOperation extends CommandOperation<CursorResponse> {
118129
timeoutContext: TimeoutContext
119130
): Promise<CursorResponse> {
120131
this.server = server;
132+
const serverWireVersion = maxWireVersion(server);
121133

122134
const options = this.options;
123135

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

130143
return await server.command(
131144
this.ns,

0 commit comments

Comments
 (0)