@@ -28,6 +28,7 @@ import (
2828 "go.mongodb.org/mongo-driver/v2/mongo"
2929 "go.mongodb.org/mongo-driver/v2/mongo/options"
3030 "go.mongodb.org/mongo-driver/v2/mongo/readpref"
31+ "go.mongodb.org/mongo-driver/v2/mongo/writeconcern"
3132 "go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore"
3233 "go.mongodb.org/mongo-driver/v2/x/mongo/driver"
3334 "go.mongodb.org/mongo-driver/v2/x/mongo/driver/wiremessage"
@@ -718,6 +719,77 @@ func TestClient(t *testing.T) {
718719 })
719720 }
720721 })
722+ mtBulkWriteOpts := mtest .NewOptions ().MinServerVersion ("8.0" ).AtlasDataLake (false ).ClientType (mtest .Pinned )
723+ mt .RunOpts ("bulk write with nil filter" , mtBulkWriteOpts , func (mt * mtest.T ) {
724+ mt .Parallel ()
725+
726+ testCases := []struct {
727+ name string
728+ models * mongo.ClientWriteModels
729+ }{
730+ {
731+ name : "DeleteOne" ,
732+ models : (& mongo.ClientWriteModels {}).AppendDeleteOne ("foo" , "bar" , mongo .NewClientDeleteOneModel ()),
733+ },
734+ {
735+ name : "DeleteMany" ,
736+ models : (& mongo.ClientWriteModels {}).AppendDeleteMany ("foo" , "bar" , mongo .NewClientDeleteManyModel ()),
737+ },
738+ {
739+ name : "UpdateOne" ,
740+ models : (& mongo.ClientWriteModels {}).AppendUpdateOne ("foo" , "bar" , mongo .NewClientUpdateOneModel ()),
741+ },
742+ {
743+ name : "UpdateMany" ,
744+ models : (& mongo.ClientWriteModels {}).AppendUpdateMany ("foo" , "bar" , mongo .NewClientUpdateManyModel ()),
745+ },
746+ }
747+ for _ , tc := range testCases {
748+ tc := tc
749+
750+ mt .Run (tc .name , func (mt * mtest.T ) {
751+ mt .Parallel ()
752+
753+ _ , err := mt .Client .BulkWrite (context .Background (), tc .models )
754+ require .ErrorContains (mt , err , "filter is required" )
755+ })
756+ }
757+ })
758+ mt .RunOpts ("bulk write with write concern" , mtBulkWriteOpts , func (mt * mtest.T ) {
759+ mt .Parallel ()
760+
761+ testCases := []struct {
762+ name string
763+ opts * options.ClientBulkWriteOptionsBuilder
764+ want bool
765+ }{
766+ {
767+ name : "unacknowledged" ,
768+ opts : options .ClientBulkWrite ().SetWriteConcern (writeconcern .Unacknowledged ()).SetOrdered (false ),
769+ want : false ,
770+ },
771+ {
772+ name : "acknowledged" ,
773+ want : true ,
774+ },
775+ }
776+ for _ , tc := range testCases {
777+ tc := tc
778+
779+ mt .Run (tc .name , func (mt * mtest.T ) {
780+ mt .Parallel ()
781+
782+ var models * mongo.ClientWriteModels
783+
784+ insertOneModel := mongo .NewClientInsertOneModel ().SetDocument (bson.D {{"x" , 1 }})
785+ models = (& mongo.ClientWriteModels {}).AppendInsertOne ("foo" , "bar" , insertOneModel )
786+ res , err := mt .Client .BulkWrite (context .Background (), models , tc .opts )
787+ require .NoError (mt , err , "BulkWrite error: %v" , err )
788+ require .NotNil (mt , res , "expected a ClientBulkWriteResult" )
789+ assert .Equal (mt , res .Acknowledged , tc .want , "expected Acknowledged: %v, got: %v" , tc .want , res .Acknowledged )
790+ })
791+ }
792+ })
721793}
722794
723795func TestClient_BSONOptions (t * testing.T ) {
0 commit comments