@mongosh/shell-api 3.13.0 → 3.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
 
3
3
  import type { Agent } from 'https';
4
+ import type { AutocompletionContext } from '@mongodb-js/mongodb-ts-autocomplete';
4
5
  import { Binary } from 'bson';
5
6
  import { BSONRegExp } from 'bson';
6
7
  import { BSONSymbol } from 'bson';
@@ -2929,6 +2930,7 @@ declare class Collection<M extends GenericServerSideSchema = GenericServerSideSc
2929
2930
  _mongo: Mongo<M>;
2930
2931
  _database: DatabaseWithSchema<M, D>;
2931
2932
  _name: N;
2933
+ _cachedSampleDocs: Document_2[];
2932
2934
  constructor(mongo: Mongo<M>, database: DatabaseWithSchema<M, D> | Database<M, D>, name: N);
2933
2935
  [namespaceInfo](): Namespace;
2934
2936
  [asPrintable](): string;
@@ -3188,6 +3190,13 @@ declare class Collection<M extends GenericServerSideSchema = GenericServerSideSc
3188
3190
  */
3189
3191
  getShardDistribution(): CommandResult<GetShardDistributionResult>;
3190
3192
  /*
3193
+ Returns a document containing the shards where this collection is located as well as whether the collection itself is sharded.
3194
+ */
3195
+ getShardLocation(): {
3196
+ shards: string[];
3197
+ sharded: boolean;
3198
+ };
3199
+ /*
3191
3200
  Opens a change stream cursor on the collection
3192
3201
  */
3193
3202
  watch(pipeline?: Document_2[] | ChangeStreamOptions, options?: ChangeStreamOptions): ChangeStreamCursor;
@@ -3243,6 +3252,8 @@ declare class Collection<M extends GenericServerSideSchema = GenericServerSideSc
3243
3252
  Updates the sepecified search index.
3244
3253
  */
3245
3254
  updateSearchIndex(indexName: string, definition: Document_2): void;
3255
+ _getSampleDocs(): Promise<Document_2[]>;
3256
+ _getSampleDocsForCompletion(): Promise<Document_2[]>;
3246
3257
  }
3247
3258
 
3248
3259
  /**
@@ -4520,23 +4531,23 @@ declare class Cursor extends AggregateOrFindCursor<ServiceProviderFindCursor> {
4520
4531
  /*
4521
4532
  Adds OP_QUERY wire protocol flags, such as the tailable flag, to change the behavior of queries. Accepts: DBQuery.Option fields tailable, slaveOk, noTimeout, awaitData, exhaust, partial.
4522
4533
  */
4523
- addOption(optionFlagNumber: number): Cursor;
4534
+ addOption(optionFlagNumber: number): this;
4524
4535
  /*
4525
4536
  Sets the 'allowDiskUse' option. If no argument is passed, the default is true.
4526
4537
  */
4527
- allowDiskUse(allow?: boolean): Cursor;
4538
+ allowDiskUse(allow?: boolean): this;
4528
4539
  /*
4529
4540
  Sets the 'partial' option to true.
4530
4541
  */
4531
- allowPartialResults(): Cursor;
4542
+ allowPartialResults(): this;
4532
4543
  /*
4533
4544
  Specifies the collation for the cursor returned by the db.collection.find(). To use, append to the db.collection.find().
4534
4545
  */
4535
- collation(spec: CollationOptions): Cursor;
4546
+ collation(spec: CollationOptions): this;
4536
4547
  /*
4537
4548
  Adds a comment field to the query.
4538
4549
  */
4539
- comment(cmt: string): Cursor;
4550
+ comment(cmt: string): this;
4540
4551
  /*
4541
4552
  Counts the number of documents referenced by a cursor.
4542
4553
  */
@@ -4548,23 +4559,23 @@ declare class Cursor extends AggregateOrFindCursor<ServiceProviderFindCursor> {
4548
4559
  /*
4549
4560
  Call this method on a query to override MongoDB’s default index selection and query optimization process. Use db.collection.getIndexes() to return the list of current indexes on a collection.
4550
4561
  */
4551
- hint(index: string): Cursor;
4562
+ hint(index: string): this;
4552
4563
  /*
4553
4564
  Use the limit() method on a cursor to specify the maximum number of documents the cursor will return.
4554
4565
  */
4555
- limit(value: number): Cursor;
4566
+ limit(value: number): this;
4556
4567
  /*
4557
4568
  Specifies the exclusive upper bound for a specific index in order to constrain the results of find(). max() provides a way to specify an upper bound on compound key indexes.
4558
4569
  */
4559
- max(indexBounds: Document_2): Cursor;
4570
+ max(indexBounds: Document_2): this;
4560
4571
  /*
4561
4572
  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)
4562
4573
  */
4563
- maxAwaitTimeMS(value: number): Cursor;
4574
+ maxAwaitTimeMS(value: number): this;
4564
4575
  /*
4565
4576
  Specifies the inclusive lower bound for a specific index in order to constrain the results of find(). min() provides a way to specify lower bounds on compound key indexes.
4566
4577
  */
4567
- min(indexBounds: Document_2): Cursor;
4578
+ min(indexBounds: Document_2): this;
4568
4579
  /*
4569
4580
  The next document in the cursor returned by the db.collection.find() method. NOTE: if the cursor is tailable with awaitData then hasNext will block until a document is returned. To check if a document is in the cursor's batch without waiting, use tryNext instead
4570
4581
  */
@@ -4572,19 +4583,19 @@ declare class Cursor extends AggregateOrFindCursor<ServiceProviderFindCursor> {
4572
4583
  /*
4573
4584
  Instructs the server to avoid closing a cursor automatically after a period of inactivity.
4574
4585
  */
4575
- noCursorTimeout(): Cursor;
4586
+ noCursorTimeout(): this;
4576
4587
  /*
4577
4588
  Sets oplogReplay cursor flag to true.
4578
4589
  */
4579
- oplogReplay(): Cursor;
4590
+ oplogReplay(): this;
4580
4591
  /*
4581
4592
  Append readPref() to a cursor to control how the client routes the query to members of the replica set.
4582
4593
  */
4583
- readPref(mode: ReadPreferenceLike, tagSet?: TagSet[], hedgeOptions?: HedgeOptions): Cursor;
4594
+ readPref(mode: ReadPreferenceLike, tagSet?: TagSet[], hedgeOptions?: HedgeOptions): this;
4584
4595
  /*
4585
4596
  Modifies the cursor to return index keys rather than the documents.
4586
4597
  */
4587
- returnKey(enabled: boolean): Cursor;
4598
+ returnKey(enabled: boolean): this;
4588
4599
  /*
4589
4600
  A count of the number of documents that match the db.collection.find() query after applying any cursor.skip() and cursor.limit() methods.
4590
4601
  */
@@ -4594,7 +4605,7 @@ declare class Cursor extends AggregateOrFindCursor<ServiceProviderFindCursor> {
4594
4605
  */
4595
4606
  tailable(opts?: {
4596
4607
  awaitData: boolean;
4597
- }): Cursor;
4608
+ }): this;
4598
4609
  /*
4599
4610
  deprecated, non-functional
4600
4611
  */
@@ -4602,11 +4613,11 @@ declare class Cursor extends AggregateOrFindCursor<ServiceProviderFindCursor> {
4602
4613
  /*
4603
4614
  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.
4604
4615
  */
4605
- showRecordId(): Cursor;
4616
+ showRecordId(): this;
4606
4617
  /*
4607
4618
  Specify a read concern for the db.collection.find() method.
4608
4619
  */
4609
- readConcern(level: ReadConcernLevel): Cursor;
4620
+ readConcern(level: ReadConcernLevel): this;
4610
4621
  }
4611
4622
 
4612
4623
  /** @public */
@@ -5629,6 +5640,7 @@ declare class ExplainableCursor_2 extends Cursor {
5629
5640
  _explained: any;
5630
5641
  constructor(mongo: Mongo, cursor: Cursor, verbosity: ExplainVerbosityLike);
5631
5642
  [asPrintable](): Promise<any>;
5643
+ finish(): Promise<any>;
5632
5644
  }
5633
5645
 
5634
5646
  /** @public */
@@ -6661,6 +6673,7 @@ declare interface ModifyResult<TSchema = Document_2> {
6661
6673
  export declare class Mongo<M extends GenericServerSideSchema = GenericServerSideSchema> extends ShellApiClass {
6662
6674
  private __serviceProvider;
6663
6675
  readonly _databases: Record<StringKey<M>, DatabaseWithSchema<M>>;
6676
+ private _connectionId;
6664
6677
  _instanceState: ShellInstanceState;
6665
6678
  _connectionInfo: ConnectionInfo;
6666
6679
  private _explicitEncryptionOnly;
@@ -6691,6 +6704,7 @@ export declare class Mongo<M extends GenericServerSideSchema = GenericServerSide
6691
6704
  Returns the specified Collection of the Mongo object.
6692
6705
  */
6693
6706
  getCollection<KD extends StringKey<M>, KC extends StringKey<M[KD]>>(name: `${KD}.${KC}`): CollectionWithSchema<M, M[KD], M[KD][KC]>;
6707
+ _getConnectionId(): string;
6694
6708
  /*
6695
6709
  Returns the connection string for current session
6696
6710
  */
@@ -7288,6 +7302,7 @@ declare interface MongoDBOIDCLogEventsMap {
7288
7302
  }) => void;
7289
7303
  'mongodb-oidc-plugin:state-updated': (event: {
7290
7304
  updateId: number;
7305
+ tokenSetId: string;
7291
7306
  timerDuration: number | undefined;
7292
7307
  }) => void;
7293
7308
  'mongodb-oidc-plugin:local-redirect-accessed': (event: {
@@ -7341,10 +7356,14 @@ declare interface MongoDBOIDCLogEventsMap {
7341
7356
  'mongodb-oidc-plugin:open-browser-complete': () => void;
7342
7357
  'mongodb-oidc-plugin:notify-device-flow': () => void;
7343
7358
  'mongodb-oidc-plugin:auth-attempt-started': (event: {
7359
+ authStateId: string;
7344
7360
  flow: string;
7345
7361
  }) => void;
7346
- 'mongodb-oidc-plugin:auth-attempt-succeeded': () => void;
7362
+ 'mongodb-oidc-plugin:auth-attempt-succeeded': (event: {
7363
+ authStateId: string;
7364
+ }) => void;
7347
7365
  'mongodb-oidc-plugin:auth-attempt-failed': (event: {
7366
+ authStateId: string;
7348
7367
  error: string;
7349
7368
  }) => void;
7350
7369
  'mongodb-oidc-plugin:refresh-skipped': (event: {
@@ -7366,12 +7385,15 @@ declare interface MongoDBOIDCLogEventsMap {
7366
7385
  refreshToken: string | null;
7367
7386
  }) => void;
7368
7387
  'mongodb-oidc-plugin:skip-auth-attempt': (event: {
7388
+ authStateId: string;
7369
7389
  reason: string;
7370
7390
  }) => void;
7371
7391
  'mongodb-oidc-plugin:auth-failed': (event: {
7392
+ authStateId: string;
7372
7393
  error: string;
7373
7394
  }) => void;
7374
7395
  'mongodb-oidc-plugin:auth-succeeded': (event: {
7396
+ authStateId: string;
7375
7397
  tokenType: string | null;
7376
7398
  refreshToken: string | null;
7377
7399
  expiresAt: string | null;
@@ -7381,6 +7403,30 @@ declare interface MongoDBOIDCLogEventsMap {
7381
7403
  idToken: string | undefined;
7382
7404
  refreshToken: string | undefined;
7383
7405
  };
7406
+ forceRefreshOrReauth: boolean;
7407
+ willRetryWithForceRefreshOrReauth: boolean;
7408
+ tokenSetId: string;
7409
+ }) => void;
7410
+ 'mongodb-oidc-plugin:request-token-started': (event: {
7411
+ authStateId: string;
7412
+ isCurrentAuthAttemptSet: boolean;
7413
+ tokenSetId: string | undefined;
7414
+ username: string | undefined;
7415
+ issuer: string;
7416
+ clientId: string;
7417
+ requestScopes: string[] | undefined;
7418
+ }) => void;
7419
+ 'mongodb-oidc-plugin:request-token-ended': (event: {
7420
+ authStateId: string;
7421
+ isCurrentAuthAttemptSet: boolean;
7422
+ tokenSetId: string | undefined;
7423
+ username: string | undefined;
7424
+ issuer: string;
7425
+ clientId: string;
7426
+ requestScopes: string[] | undefined;
7427
+ }) => void;
7428
+ 'mongodb-oidc-plugin:discarding-token-set': (event: {
7429
+ tokenSetId: string;
7384
7430
  }) => void;
7385
7431
  'mongodb-oidc-plugin:destroyed': () => void;
7386
7432
  'mongodb-oidc-plugin:missing-id-token': () => void;
@@ -7739,7 +7785,7 @@ declare interface MongoshBusEventsMap extends ConnectEventMap {
7739
7785
  'mongosh:crypt-library-load-found': (ev: CryptLibraryFoundEvent) => void;
7740
7786
  'mongosh:closed': () => void;
7741
7787
  'mongosh:eval-complete': () => void;
7742
- 'mongosh:autocompletion-complete': () => void;
7788
+ 'mongosh:autocompletion-complete': (replResults: string[], mongoshResults: string[]) => void;
7743
7789
  'mongosh:interrupt-complete': () => void;
7744
7790
  'mongosh-snippets:loaded': (ev: SnippetsLoadedEvent) => void;
7745
7791
  'mongosh-snippets:npm-lookup': (ev: SnippetsNpmLookupEvent) => void;
@@ -9370,6 +9416,8 @@ declare class ShellInstanceState {
9370
9416
  emitApiCallWithArgs(event: ApiEventWithArguments): void;
9371
9417
  emitApiCall(event: Omit<ApiEvent, 'callDepth'>): void;
9372
9418
  setEvaluationListener(listener: EvaluationListener): void;
9419
+ getMongoByConnectionId(connectionId: string): Mongo;
9420
+ getAutocompletionContext(): AutocompletionContext;
9373
9421
  getAutocompleteParameters(): AutocompleteParameters;
9374
9422
  apiVersionInfo(): Required<ServerApi> | undefined;
9375
9423
  onInterruptExecution(): Promise<boolean>;
package/lib/api-raw.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
 
3
3
  import type { Agent } from 'https';
4
+ import type { AutocompletionContext } from '@mongodb-js/mongodb-ts-autocomplete';
4
5
  import { Binary } from 'bson';
5
6
  import { BSONRegExp } from 'bson';
6
7
  import { BSONSymbol } from 'bson';
@@ -2848,6 +2849,7 @@ declare class Collection<M extends GenericServerSideSchema = GenericServerSideSc
2848
2849
  _mongo: Mongo<M>;
2849
2850
  _database: DatabaseWithSchema<M, D>;
2850
2851
  _name: N;
2852
+ _cachedSampleDocs: Document_2[];
2851
2853
  constructor(mongo: Mongo<M>, database: DatabaseWithSchema<M, D> | Database<M, D>, name: N);
2852
2854
  [namespaceInfo](): Namespace;
2853
2855
  [asPrintable](): string;
@@ -2923,6 +2925,10 @@ declare class Collection<M extends GenericServerSideSchema = GenericServerSideSc
2923
2925
  getShardVersion(): Promise<Document_2>;
2924
2926
  _getShardedCollectionInfo(config: DatabaseWithSchema<M, D>, collStats: Document_2[]): Promise<Document_2>;
2925
2927
  getShardDistribution(): Promise<CommandResult<GetShardDistributionResult>>;
2928
+ getShardLocation(): Promise<{
2929
+ shards: string[];
2930
+ sharded: boolean;
2931
+ }>;
2926
2932
  watch(pipeline?: Document_2[] | ChangeStreamOptions, options?: ChangeStreamOptions): Promise<ChangeStreamCursor>;
2927
2933
  hideIndex(index: string | Document_2): Promise<Document_2>;
2928
2934
  unhideIndex(index: string | Document_2): Promise<Document_2>;
@@ -2937,6 +2943,8 @@ declare class Collection<M extends GenericServerSideSchema = GenericServerSideSc
2937
2943
  createSearchIndexes(specs: SearchIndexDescription[]): Promise<string[]>;
2938
2944
  dropSearchIndex(indexName: string): Promise<void>;
2939
2945
  updateSearchIndex(indexName: string, definition: Document_2): Promise<void>;
2946
+ _getSampleDocs(): Promise<Document_2[]>;
2947
+ _getSampleDocsForCompletion(): Promise<Document_2[]>;
2940
2948
  }
2941
2949
 
2942
2950
  /**
@@ -4238,30 +4246,30 @@ declare class Cursor extends AggregateOrFindCursor<ServiceProviderFindCursor> {
4238
4246
  constructor(mongo: Mongo, cursor: ServiceProviderFindCursor);
4239
4247
  toJSON(): void;
4240
4248
  private _addFlag;
4241
- addOption(optionFlagNumber: number): Cursor;
4242
- allowDiskUse(allow?: boolean): Cursor;
4243
- allowPartialResults(): Cursor;
4244
- collation(spec: CollationOptions): Cursor;
4245
- comment(cmt: string): Cursor;
4249
+ addOption(optionFlagNumber: number): this;
4250
+ allowDiskUse(allow?: boolean): this;
4251
+ allowPartialResults(): this;
4252
+ collation(spec: CollationOptions): this;
4253
+ comment(cmt: string): this;
4246
4254
  count(): Promise<number>;
4247
4255
  hasNext(): Promise<boolean>;
4248
- hint(index: string): Cursor;
4249
- limit(value: number): Cursor;
4250
- max(indexBounds: Document_2): Cursor;
4251
- maxAwaitTimeMS(value: number): Cursor;
4252
- min(indexBounds: Document_2): Cursor;
4256
+ hint(index: string): this;
4257
+ limit(value: number): this;
4258
+ max(indexBounds: Document_2): this;
4259
+ maxAwaitTimeMS(value: number): this;
4260
+ min(indexBounds: Document_2): this;
4253
4261
  next(): Promise<Document_2 | null>;
4254
- noCursorTimeout(): Cursor;
4255
- oplogReplay(): Cursor;
4256
- readPref(mode: ReadPreferenceLike, tagSet?: TagSet[], hedgeOptions?: HedgeOptions): Cursor;
4257
- returnKey(enabled: boolean): Cursor;
4262
+ noCursorTimeout(): this;
4263
+ oplogReplay(): this;
4264
+ readPref(mode: ReadPreferenceLike, tagSet?: TagSet[], hedgeOptions?: HedgeOptions): this;
4265
+ returnKey(enabled: boolean): this;
4258
4266
  size(): Promise<number>;
4259
4267
  tailable(opts?: {
4260
4268
  awaitData: boolean;
4261
- }): Cursor;
4269
+ }): this;
4262
4270
  maxScan(): void;
4263
- showRecordId(): Cursor;
4264
- readConcern(level: ReadConcernLevel): Cursor;
4271
+ showRecordId(): this;
4272
+ readConcern(level: ReadConcernLevel): this;
4265
4273
  }
4266
4274
 
4267
4275
  /** @public */
@@ -5035,6 +5043,7 @@ declare class ExplainableCursor_2 extends Cursor {
5035
5043
  _explained: any;
5036
5044
  constructor(mongo: Mongo, cursor: Cursor, verbosity: ExplainVerbosityLike);
5037
5045
  [asPrintable](): Promise<any>;
5046
+ finish(): Promise<any>;
5038
5047
  }
5039
5048
 
5040
5049
  /** @public */
@@ -6060,6 +6069,7 @@ declare interface ModifyResult<TSchema = Document_2> {
6060
6069
  export declare class Mongo<M extends GenericServerSideSchema = GenericServerSideSchema> extends ShellApiClass {
6061
6070
  private __serviceProvider;
6062
6071
  readonly _databases: Record<StringKey<M>, DatabaseWithSchema<M>>;
6072
+ private _connectionId;
6063
6073
  _instanceState: ShellInstanceState;
6064
6074
  _connectionInfo: ConnectionInfo;
6065
6075
  private _explicitEncryptionOnly;
@@ -6081,6 +6091,7 @@ export declare class Mongo<M extends GenericServerSideSchema = GenericServerSide
6081
6091
  _getDb<K extends StringKey<M>>(name: K): DatabaseWithSchema<M, M[K]>;
6082
6092
  getDB<K extends StringKey<M>>(db: K): DatabaseWithSchema<M, M[K]>;
6083
6093
  getCollection<KD extends StringKey<M>, KC extends StringKey<M[KD]>>(name: `${KD}.${KC}`): CollectionWithSchema<M, M[KD], M[KD][KC]>;
6094
+ _getConnectionId(): string;
6084
6095
  getURI(): string;
6085
6096
  use(db: StringKey<M>): string;
6086
6097
  _listDatabases(opts?: ListDatabasesOptions): Promise<{
@@ -6609,6 +6620,7 @@ declare interface MongoDBOIDCLogEventsMap {
6609
6620
  }) => void;
6610
6621
  'mongodb-oidc-plugin:state-updated': (event: {
6611
6622
  updateId: number;
6623
+ tokenSetId: string;
6612
6624
  timerDuration: number | undefined;
6613
6625
  }) => void;
6614
6626
  'mongodb-oidc-plugin:local-redirect-accessed': (event: {
@@ -6662,10 +6674,14 @@ declare interface MongoDBOIDCLogEventsMap {
6662
6674
  'mongodb-oidc-plugin:open-browser-complete': () => void;
6663
6675
  'mongodb-oidc-plugin:notify-device-flow': () => void;
6664
6676
  'mongodb-oidc-plugin:auth-attempt-started': (event: {
6677
+ authStateId: string;
6665
6678
  flow: string;
6666
6679
  }) => void;
6667
- 'mongodb-oidc-plugin:auth-attempt-succeeded': () => void;
6680
+ 'mongodb-oidc-plugin:auth-attempt-succeeded': (event: {
6681
+ authStateId: string;
6682
+ }) => void;
6668
6683
  'mongodb-oidc-plugin:auth-attempt-failed': (event: {
6684
+ authStateId: string;
6669
6685
  error: string;
6670
6686
  }) => void;
6671
6687
  'mongodb-oidc-plugin:refresh-skipped': (event: {
@@ -6687,12 +6703,15 @@ declare interface MongoDBOIDCLogEventsMap {
6687
6703
  refreshToken: string | null;
6688
6704
  }) => void;
6689
6705
  'mongodb-oidc-plugin:skip-auth-attempt': (event: {
6706
+ authStateId: string;
6690
6707
  reason: string;
6691
6708
  }) => void;
6692
6709
  'mongodb-oidc-plugin:auth-failed': (event: {
6710
+ authStateId: string;
6693
6711
  error: string;
6694
6712
  }) => void;
6695
6713
  'mongodb-oidc-plugin:auth-succeeded': (event: {
6714
+ authStateId: string;
6696
6715
  tokenType: string | null;
6697
6716
  refreshToken: string | null;
6698
6717
  expiresAt: string | null;
@@ -6702,6 +6721,30 @@ declare interface MongoDBOIDCLogEventsMap {
6702
6721
  idToken: string | undefined;
6703
6722
  refreshToken: string | undefined;
6704
6723
  };
6724
+ forceRefreshOrReauth: boolean;
6725
+ willRetryWithForceRefreshOrReauth: boolean;
6726
+ tokenSetId: string;
6727
+ }) => void;
6728
+ 'mongodb-oidc-plugin:request-token-started': (event: {
6729
+ authStateId: string;
6730
+ isCurrentAuthAttemptSet: boolean;
6731
+ tokenSetId: string | undefined;
6732
+ username: string | undefined;
6733
+ issuer: string;
6734
+ clientId: string;
6735
+ requestScopes: string[] | undefined;
6736
+ }) => void;
6737
+ 'mongodb-oidc-plugin:request-token-ended': (event: {
6738
+ authStateId: string;
6739
+ isCurrentAuthAttemptSet: boolean;
6740
+ tokenSetId: string | undefined;
6741
+ username: string | undefined;
6742
+ issuer: string;
6743
+ clientId: string;
6744
+ requestScopes: string[] | undefined;
6745
+ }) => void;
6746
+ 'mongodb-oidc-plugin:discarding-token-set': (event: {
6747
+ tokenSetId: string;
6705
6748
  }) => void;
6706
6749
  'mongodb-oidc-plugin:destroyed': () => void;
6707
6750
  'mongodb-oidc-plugin:missing-id-token': () => void;
@@ -7062,7 +7105,7 @@ declare interface MongoshBusEventsMap extends ConnectEventMap {
7062
7105
  'mongosh:crypt-library-load-found': (ev: CryptLibraryFoundEvent) => void;
7063
7106
  'mongosh:closed': () => void;
7064
7107
  'mongosh:eval-complete': () => void;
7065
- 'mongosh:autocompletion-complete': () => void;
7108
+ 'mongosh:autocompletion-complete': (replResults: string[], mongoshResults: string[]) => void;
7066
7109
  'mongosh:interrupt-complete': () => void;
7067
7110
  'mongosh-snippets:loaded': (ev: SnippetsLoadedEvent) => void;
7068
7111
  'mongosh-snippets:npm-lookup': (ev: SnippetsNpmLookupEvent) => void;
@@ -8435,6 +8478,8 @@ declare class ShellInstanceState {
8435
8478
  emitApiCallWithArgs(event: ApiEventWithArguments): void;
8436
8479
  emitApiCall(event: Omit<ApiEvent, 'callDepth'>): void;
8437
8480
  setEvaluationListener(listener: EvaluationListener): void;
8481
+ getMongoByConnectionId(connectionId: string): Mongo;
8482
+ getAutocompletionContext(): AutocompletionContext;
8438
8483
  getAutocompleteParameters(): AutocompleteParameters;
8439
8484
  apiVersionInfo(): Required<ServerApi> | undefined;
8440
8485
  onInterruptExecution(): Promise<boolean>;
@@ -16,6 +16,7 @@ export declare class Collection<M extends GenericServerSideSchema = GenericServe
16
16
  _mongo: Mongo<M>;
17
17
  _database: DatabaseWithSchema<M, D>;
18
18
  _name: N;
19
+ _cachedSampleDocs: Document[];
19
20
  constructor(mongo: Mongo<M>, database: DatabaseWithSchema<M, D> | Database<M, D>, name: N);
20
21
  [namespaceInfo](): Namespace;
21
22
  [asPrintable](): string;
@@ -91,6 +92,10 @@ export declare class Collection<M extends GenericServerSideSchema = GenericServe
91
92
  getShardVersion(): Promise<Document>;
92
93
  _getShardedCollectionInfo(config: DatabaseWithSchema<M, D>, collStats: Document[]): Promise<Document>;
93
94
  getShardDistribution(): Promise<CommandResult<GetShardDistributionResult>>;
95
+ getShardLocation(): Promise<{
96
+ shards: string[];
97
+ sharded: boolean;
98
+ }>;
94
99
  watch(pipeline?: Document[] | ChangeStreamOptions, options?: ChangeStreamOptions): Promise<ChangeStreamCursor>;
95
100
  hideIndex(index: string | Document): Promise<Document>;
96
101
  unhideIndex(index: string | Document): Promise<Document>;
@@ -105,6 +110,8 @@ export declare class Collection<M extends GenericServerSideSchema = GenericServe
105
110
  createSearchIndexes(specs: SearchIndexDescription[]): Promise<string[]>;
106
111
  dropSearchIndex(indexName: string): Promise<void>;
107
112
  updateSearchIndex(indexName: string, definition: Document): Promise<void>;
113
+ _getSampleDocs(): Promise<Document[]>;
114
+ _getSampleDocsForCompletion(): Promise<Document[]>;
108
115
  }
109
116
  export type GetShardDistributionResult = {
110
117
  Totals: {
package/lib/collection.js CHANGED
@@ -114,6 +114,7 @@ let Collection = (() => {
114
114
  let _validate_decorators;
115
115
  let _getShardVersion_decorators;
116
116
  let _getShardDistribution_decorators;
117
+ let _getShardLocation_decorators;
117
118
  let _watch_decorators;
118
119
  let _hideIndex_decorators;
119
120
  let _unhideIndex_decorators;
@@ -129,6 +130,7 @@ let Collection = (() => {
129
130
  constructor(mongo, database, name) {
130
131
  super();
131
132
  this._mongo = __runInitializers(this, _instanceExtraInitializers);
133
+ this._cachedSampleDocs = [];
132
134
  this._mongo = mongo;
133
135
  this._database = database;
134
136
  this._name = name;
@@ -1058,6 +1060,35 @@ let Collection = (() => {
1058
1060
  result.Totals = totalValue;
1059
1061
  return new index_1.CommandResult('StatsResult', result);
1060
1062
  }
1063
+ async getShardLocation() {
1064
+ this._emitCollectionApiCall('getShardLocation', {});
1065
+ const result = await (await this._database.aggregate([
1066
+ {
1067
+ $listClusterCatalog: {
1068
+ shards: true,
1069
+ },
1070
+ },
1071
+ {
1072
+ $match: {
1073
+ ns: this.getFullName(),
1074
+ },
1075
+ },
1076
+ {
1077
+ $project: {
1078
+ _id: 0,
1079
+ shards: 1,
1080
+ sharded: 1,
1081
+ },
1082
+ },
1083
+ ])).toArray();
1084
+ if (result.length > 0) {
1085
+ return {
1086
+ shards: result[0].shards,
1087
+ sharded: result[0].sharded,
1088
+ };
1089
+ }
1090
+ throw new errors_1.MongoshRuntimeError(`Error finding location information for ${this.getFullName()}`, errors_1.CommonErrors.CommandFailed);
1091
+ }
1061
1092
  async watch(pipeline = [], options = {}) {
1062
1093
  if (!Array.isArray(pipeline)) {
1063
1094
  options = pipeline;
@@ -1102,7 +1133,7 @@ let Collection = (() => {
1102
1133
  }
1103
1134
  async checkMetadataConsistency(options = {}) {
1104
1135
  this._emitCollectionApiCall('checkMetadataConsistency', { options });
1105
- return this._database._runCursorCommand({
1136
+ return await this._database._runCursorCommand({
1106
1137
  checkMetadataConsistency: this._name,
1107
1138
  });
1108
1139
  }
@@ -1164,6 +1195,25 @@ let Collection = (() => {
1164
1195
  this._emitCollectionApiCall('updateSearchIndex', { indexName, definition });
1165
1196
  return await this._mongo._serviceProvider.updateSearchIndex(this._database._name, this._name, indexName, definition);
1166
1197
  }
1198
+ async _getSampleDocs() {
1199
+ this._cachedSampleDocs = await (await this.aggregate([{ $sample: { size: 10 } }], {
1200
+ allowDiskUse: true,
1201
+ maxTimeMS: 1000,
1202
+ readPreference: 'secondaryPreferred',
1203
+ })).toArray();
1204
+ return this._cachedSampleDocs;
1205
+ }
1206
+ async _getSampleDocsForCompletion() {
1207
+ return await Promise.race([
1208
+ (async () => {
1209
+ return await this._getSampleDocs();
1210
+ })(),
1211
+ (async () => {
1212
+ await new Promise((resolve) => { var _a, _b; return (_b = (_a = setTimeout(resolve, 200)) === null || _a === void 0 ? void 0 : _a.unref) === null || _b === void 0 ? void 0 : _b.call(_a); });
1213
+ return this._cachedSampleDocs;
1214
+ })(),
1215
+ ]);
1216
+ }
1167
1217
  };
1168
1218
  __setFunctionName(_classThis, "Collection");
1169
1219
  (() => {
@@ -1224,6 +1274,7 @@ let Collection = (() => {
1224
1274
  _validate_decorators = [decorators_1.returnsPromise, (0, decorators_1.apiVersions)([])];
1225
1275
  _getShardVersion_decorators = [decorators_1.returnsPromise, (0, decorators_1.topologies)([enums_1.Topologies.Sharded]), (0, decorators_1.apiVersions)([])];
1226
1276
  _getShardDistribution_decorators = [decorators_1.returnsPromise, (0, decorators_1.topologies)([enums_1.Topologies.Sharded]), (0, decorators_1.apiVersions)([])];
1277
+ _getShardLocation_decorators = [decorators_1.returnsPromise, (0, decorators_1.topologies)([enums_1.Topologies.Sharded]), (0, decorators_1.apiVersions)([]), (0, decorators_1.serverVersions)(['8.0.10', enums_1.ServerVersions.latest])];
1227
1278
  _watch_decorators = [(0, decorators_1.serverVersions)(['3.1.0', enums_1.ServerVersions.latest]), (0, decorators_1.topologies)([enums_1.Topologies.ReplSet, enums_1.Topologies.Sharded]), (0, decorators_1.apiVersions)([1]), decorators_1.returnsPromise];
1228
1279
  _hideIndex_decorators = [(0, decorators_1.serverVersions)(['4.4.0', enums_1.ServerVersions.latest]), decorators_1.returnsPromise, (0, decorators_1.apiVersions)([1])];
1229
1280
  _unhideIndex_decorators = [(0, decorators_1.serverVersions)(['4.4.0', enums_1.ServerVersions.latest]), decorators_1.returnsPromise, (0, decorators_1.apiVersions)([1])];
@@ -1290,6 +1341,7 @@ let Collection = (() => {
1290
1341
  __esDecorate(_classThis, null, _validate_decorators, { kind: "method", name: "validate", static: false, private: false, access: { has: obj => "validate" in obj, get: obj => obj.validate }, metadata: _metadata }, null, _instanceExtraInitializers);
1291
1342
  __esDecorate(_classThis, null, _getShardVersion_decorators, { kind: "method", name: "getShardVersion", static: false, private: false, access: { has: obj => "getShardVersion" in obj, get: obj => obj.getShardVersion }, metadata: _metadata }, null, _instanceExtraInitializers);
1292
1343
  __esDecorate(_classThis, null, _getShardDistribution_decorators, { kind: "method", name: "getShardDistribution", static: false, private: false, access: { has: obj => "getShardDistribution" in obj, get: obj => obj.getShardDistribution }, metadata: _metadata }, null, _instanceExtraInitializers);
1344
+ __esDecorate(_classThis, null, _getShardLocation_decorators, { kind: "method", name: "getShardLocation", static: false, private: false, access: { has: obj => "getShardLocation" in obj, get: obj => obj.getShardLocation }, metadata: _metadata }, null, _instanceExtraInitializers);
1293
1345
  __esDecorate(_classThis, null, _watch_decorators, { kind: "method", name: "watch", static: false, private: false, access: { has: obj => "watch" in obj, get: obj => obj.watch }, metadata: _metadata }, null, _instanceExtraInitializers);
1294
1346
  __esDecorate(_classThis, null, _hideIndex_decorators, { kind: "method", name: "hideIndex", static: false, private: false, access: { has: obj => "hideIndex" in obj, get: obj => obj.hideIndex }, metadata: _metadata }, null, _instanceExtraInitializers);
1295
1347
  __esDecorate(_classThis, null, _unhideIndex_decorators, { kind: "method", name: "unhideIndex", static: false, private: false, access: { has: obj => "unhideIndex" in obj, get: obj => obj.unhideIndex }, metadata: _metadata }, null, _instanceExtraInitializers);