@@ -776,17 +776,73 @@ 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 := bsoncore .NewDocumentBuilder ().
822
+ AppendBoolean ("allowPartialResults" , true ).
823
+ AppendInt32 ("batchSize" , 2 ).
824
+ StartDocument ("collation" ).AppendString ("locale" , "en_US" ).FinishDocument ().
825
+ AppendString ("comment" , expectedComment ).
826
+ AppendString ("hint" , indexName ).
827
+ StartDocument ("max" ).AppendInt32 ("x" , 5 ).FinishDocument ().
828
+ AppendInt32 ("maxTimeMS" , 1000 ).
829
+ StartDocument ("min" ).AppendInt32 ("x" , 0 ).FinishDocument ().
830
+ AppendBoolean ("noCursorTimeout" , false ).
831
+ AppendBoolean ("oplogReplay" , false ).
832
+ StartDocument ("projection" ).AppendInt32 ("x" , 1 ).FinishDocument ().
833
+ AppendBoolean ("returnKey" , false ).
834
+ AppendBoolean ("showRecordId" , false ).
835
+ AppendInt64 ("skip" , 0 ).
836
+ StartDocument ("sort" ).AppendInt32 ("x" , 1 ).FinishDocument ().
837
+ Build ()
838
+
839
+ started := mt .GetStartedEvent ()
840
+ assert .NotNil (mt , started , "expected CommandStartedEvent, got nil" )
841
+
842
+ if err := compareDocs (mt , bson .Raw (optionsDoc ), started .Command ); err != nil {
843
+ mt .Fatalf ("options mismatch: %v" , err )
844
+ }
845
+
790
846
})
791
847
mt .Run ("not found" , func (mt * mtest.T ) {
792
848
initCollection (mt , mt .Coll )
0 commit comments