@@ -776,17 +776,75 @@ func TestCollection(t *testing.T) {
776
776
got := x .Int32 ()
777
777
assert .Equal (mt , int32 (1 ), got , "expected x value 1, got %v" , got )
778
778
})
779
- mt .Run ("options" , func (mt * mtest.T ) {
779
+ mt .RunOpts ("options" , mtest . NewOptions (). MinServerVersion ( "3.4" ) , func (mt * mtest.T ) {
780
780
initCollection (mt , mt .Coll )
781
- opts := options .FindOne ().SetComment ("here's a query for ya" )
782
- res , err := mt .Coll .FindOne (mtest .Background , bson.D {{"x" , 1 }}, opts ).DecodeBytes ()
781
+
782
+ // Create an index for Hint, Max, and Min options
783
+ indexView := mt .Coll .Indexes ()
784
+ indexName , err := indexView .CreateOne (context .Background (), mongo.IndexModel {
785
+ Keys : bson.D {{"x" , 1 }},
786
+ })
787
+ assert .Nil (mt , err , "CreateOne error: %v" , err )
788
+
789
+ mt .ClearEvents ()
790
+ expectedComment := "here's a query for ya"
791
+ // SetCursorType is excluded because tailable cursors can't be used with limit -1,
792
+ // which all FindOne operations set, and the nontailable setting isn't passed to the
793
+ // operation layer
794
+ // SetMaxAwaitTime affects the cursor and not the server command, so it can't be checked
795
+ // SetCursorTime and setMaxAwaitTime will be deprecated in GODRIVER-1775
796
+ opts := options .FindOne ().
797
+ SetAllowPartialResults (true ).
798
+ SetBatchSize (2 ).
799
+ SetCollation (& options.Collation {Locale : "en_US" }).
800
+ SetComment (expectedComment ).
801
+ SetHint (indexName ).
802
+ SetMax (bson.D {{"x" , int32 (5 )}}).
803
+ SetMaxTime (1 * time .Second ).
804
+ SetMin (bson.D {{"x" , int32 (0 )}}).
805
+ SetNoCursorTimeout (false ).
806
+ SetOplogReplay (false ).
807
+ SetProjection (bson.D {{"x" , int32 (1 )}}).
808
+ SetReturnKey (false ).
809
+ SetShowRecordID (false ).
810
+ SetSkip (0 ).
811
+ SetSort (bson.D {{"x" , int32 (1 )}})
812
+ res , err := mt .Coll .FindOne (mtest .Background , bson.D {}, opts ).DecodeBytes ()
783
813
assert .Nil (mt , err , "FindOne error: %v" , err )
784
814
785
815
x , err := res .LookupErr ("x" )
786
816
assert .Nil (mt , err , "x not found in document %v" , res )
787
817
assert .Equal (mt , bson .TypeInt32 , x .Type , "expected x type %v, got %v" , bson .TypeInt32 , x .Type )
788
818
got := x .Int32 ()
789
819
assert .Equal (mt , int32 (1 ), got , "expected x value 1, got %v" , got )
820
+
821
+ optionsDoc := bson.M {
822
+ "allowPartialResults" : true ,
823
+ "batchSize" : int32 (2 ),
824
+ "collation" : bson.M {"locale" : "en_US" },
825
+ "comment" : expectedComment ,
826
+ "hint" : indexName ,
827
+ "max" : bson.M {"x" : int32 (5 )},
828
+ "maxTimeMS" : int32 (1000 ),
829
+ "min" : bson.M {"x" : int32 (0 )},
830
+ "noCursorTimeout" : false ,
831
+ "oplogReplay" : false ,
832
+ "projection" : bson.M {"x" : int32 (1 )},
833
+ "returnKey" : false ,
834
+ "showRecordId" : false ,
835
+ "skip" : int64 (0 ),
836
+ "sort" : bson.M {"x" : int32 (1 )},
837
+ }
838
+ expectedOpts , err := bson .Marshal (optionsDoc )
839
+ assert .Nil (mt , err , "error marshaling expected options: %v" , err )
840
+
841
+ started := mt .GetStartedEvent ()
842
+ assert .NotNil (mt , started , "expected CommandStartedEvent, got nil" )
843
+
844
+ if err := compareDocs (mt , expectedOpts , started .Command ); err != nil {
845
+ mt .Fatalf ("options mismatch: %v" , err )
846
+ }
847
+
790
848
})
791
849
mt .Run ("not found" , func (mt * mtest.T ) {
792
850
initCollection (mt , mt .Coll )
0 commit comments