@@ -346,18 +346,37 @@ impl<T> Collection<T> {
346
346
. await
347
347
}
348
348
349
- /// Creates the given index on this collection.
350
- pub async fn create_index (
349
+ async fn create_index_common (
351
350
& self ,
352
351
index : IndexModel ,
353
352
options : impl Into < Option < CreateIndexOptions > > ,
353
+ session : impl Into < Option < & mut ClientSession > > ,
354
354
) -> Result < CreateIndexResult > {
355
355
let response = self
356
- . create_indexes_common ( vec ! [ index] , options, None )
356
+ . create_indexes_common ( vec ! [ index] , options, session )
357
357
. await ?;
358
358
Ok ( response. into ( ) )
359
359
}
360
360
361
+ /// Creates the given index on this collection.
362
+ pub async fn create_index (
363
+ & self ,
364
+ index : IndexModel ,
365
+ options : impl Into < Option < CreateIndexOptions > > ,
366
+ ) -> Result < CreateIndexResult > {
367
+ self . create_index_common ( index, options, None ) . await
368
+ }
369
+
370
+ /// Convenience method for creating a single index on an explicit session.
371
+ pub async fn create_index_with_session (
372
+ & self ,
373
+ index : IndexModel ,
374
+ options : impl Into < Option < CreateIndexOptions > > ,
375
+ session : & mut ClientSession ,
376
+ ) -> Result < CreateIndexResult > {
377
+ self . create_index_common ( index, options, session) . await
378
+ }
379
+
361
380
/// Creates the given indexes on this collection.
362
381
pub async fn create_indexes (
363
382
& self ,
@@ -367,6 +386,16 @@ impl<T> Collection<T> {
367
386
self . create_indexes_common ( indexes, options, None ) . await
368
387
}
369
388
389
+ /// Create several indexes on an explicit session.
390
+ pub async fn create_indexes_with_session (
391
+ & self ,
392
+ indexes : impl IntoIterator < Item = IndexModel > ,
393
+ options : impl Into < Option < CreateIndexOptions > > ,
394
+ session : & mut ClientSession ,
395
+ ) -> Result < CreateIndexesResult > {
396
+ self . create_indexes_common ( indexes, options, session) . await
397
+ }
398
+
370
399
/// Deletes all documents stored in the collection matching `query`.
371
400
pub async fn delete_many (
372
401
& self ,
@@ -477,7 +506,7 @@ impl<T> Collection<T> {
477
506
. await
478
507
}
479
508
480
- async fn drop_index_common (
509
+ async fn drop_indexes_common (
481
510
& self ,
482
511
name : impl Into < Option < & str > > ,
483
512
options : impl Into < Option < DropIndexOptions > > ,
@@ -495,11 +524,11 @@ impl<T> Collection<T> {
495
524
self . client ( ) . execute_operation ( drop_index, session) . await
496
525
}
497
526
498
- /// Drops the index specified by `name` from this collection.
499
- pub async fn drop_index (
527
+ async fn drop_index_common (
500
528
& self ,
501
529
name : impl AsRef < str > ,
502
530
options : impl Into < Option < DropIndexOptions > > ,
531
+ session : impl Into < Option < & mut ClientSession > > ,
503
532
) -> Result < ( ) > {
504
533
let name = name. as_ref ( ) ;
505
534
if name == "*" {
@@ -510,12 +539,40 @@ impl<T> Collection<T> {
510
539
}
511
540
. into ( ) ) ;
512
541
}
542
+ self . drop_indexes_common ( name, options, session) . await
543
+ }
544
+
545
+ /// Drops the index specified by `name` from this collection.
546
+ pub async fn drop_index (
547
+ & self ,
548
+ name : & str ,
549
+ options : impl Into < Option < DropIndexOptions > > ,
550
+ ) -> Result < ( ) > {
513
551
self . drop_index_common ( name, options, None ) . await
514
552
}
515
553
554
+ /// Drop the index specified by `name` from the collection using an explicit session.
555
+ pub async fn drop_index_with_session (
556
+ & self ,
557
+ name : & str ,
558
+ options : impl Into < Option < DropIndexOptions > > ,
559
+ session : & mut ClientSession ,
560
+ ) -> Result < ( ) > {
561
+ self . drop_index_common ( name, options, session) . await
562
+ }
563
+
516
564
/// Drops all indexes associated with this collection.
517
565
pub async fn drop_indexes ( & self , options : impl Into < Option < DropIndexOptions > > ) -> Result < ( ) > {
518
- self . drop_index_common ( None , options, None ) . await
566
+ self . drop_indexes_common ( None , options, None ) . await
567
+ }
568
+
569
+ /// Drop all indexes associated with the collection using an explicit session.
570
+ pub async fn drop_indexes_with_session (
571
+ & self ,
572
+ options : impl Into < Option < DropIndexOptions > > ,
573
+ session : & mut ClientSession ,
574
+ ) -> Result < ( ) > {
575
+ self . drop_indexes_common ( None , options, session) . await
519
576
}
520
577
521
578
/// Lists all indexes on this collection.
@@ -531,6 +588,20 @@ impl<T> Collection<T> {
531
588
. map ( |( spec, session) | Cursor :: new ( client. clone ( ) , spec, session) )
532
589
}
533
590
591
+ /// List all indexes on the collection using an explicit session.
592
+ pub async fn list_indexes_with_session (
593
+ & self ,
594
+ options : impl Into < Option < ListIndexOptions > > ,
595
+ session : & mut ClientSession ,
596
+ ) -> Result < SessionCursor < IndexModel > > {
597
+ let list_indexes = ListIndexes :: new ( self . namespace ( ) , options. into ( ) ) ;
598
+ let client = self . client ( ) ;
599
+ client
600
+ . execute_operation ( list_indexes, session)
601
+ . await
602
+ . map ( |spec| SessionCursor :: new ( client. clone ( ) , spec) )
603
+ }
604
+
534
605
async fn list_index_names_common (
535
606
& self ,
536
607
cursor : impl TryStreamExt < Ok = IndexModel , Error = Error > ,
@@ -543,15 +614,19 @@ impl<T> Collection<T> {
543
614
544
615
/// Gets the names of all indexes on the collection.
545
616
pub async fn list_index_names ( & self ) -> Result < Vec < String > > {
546
- let list_indexes = ListIndexes :: new ( self . namespace ( ) , None ) ;
547
- let client = self . client ( ) ;
548
- let cursor: Cursor < IndexModel > = client
549
- . execute_cursor_operation ( list_indexes)
550
- . await
551
- . map ( |( spec, session) | Cursor :: new ( client. clone ( ) , spec, session) ) ?;
617
+ let cursor = self . list_indexes ( None ) . await ?;
552
618
self . list_index_names_common ( cursor) . await
553
619
}
554
620
621
+ /// Gets the names of all indexes on the collection using the provided `ClientSession`.
622
+ pub async fn list_index_names_with_session (
623
+ & self ,
624
+ session : & mut ClientSession ,
625
+ ) -> Result < Vec < String > > {
626
+ let mut cursor = self . list_indexes_with_session ( None , session) . await ?;
627
+ self . list_index_names_common ( cursor. stream ( session) ) . await
628
+ }
629
+
555
630
async fn update_many_common (
556
631
& self ,
557
632
query : Document ,
0 commit comments