@@ -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,76 @@ func TestClient(t *testing.T) {
718719 })
719720 }
720721 })
722+ mt .Run ("bulk write with nil filter" , func (mt * mtest.T ) {
723+ mt .Parallel ()
724+
725+ testCases := []struct {
726+ name string
727+ models * mongo.ClientWriteModels
728+ }{
729+ {
730+ name : "DeleteOne" ,
731+ models : (& mongo.ClientWriteModels {}).AppendDeleteOne ("foo" , "bar" , mongo .NewClientDeleteOneModel ()),
732+ },
733+ {
734+ name : "DeleteMany" ,
735+ models : (& mongo.ClientWriteModels {}).AppendDeleteMany ("foo" , "bar" , mongo .NewClientDeleteManyModel ()),
736+ },
737+ {
738+ name : "UpdateOne" ,
739+ models : (& mongo.ClientWriteModels {}).AppendUpdateOne ("foo" , "bar" , mongo .NewClientUpdateOneModel ()),
740+ },
741+ {
742+ name : "UpdateMany" ,
743+ models : (& mongo.ClientWriteModels {}).AppendUpdateMany ("foo" , "bar" , mongo .NewClientUpdateManyModel ()),
744+ },
745+ }
746+ for _ , tc := range testCases {
747+ tc := tc
748+
749+ mt .Run (tc .name , func (mt * mtest.T ) {
750+ mt .Parallel ()
751+
752+ _ , err := mt .Client .BulkWrite (context .Background (), tc .models )
753+ require .ErrorContains (mt , err , "filter is required" )
754+ })
755+ }
756+ })
757+ mt .Run ("bulk write with write concern" , func (mt * mtest.T ) {
758+ mt .Parallel ()
759+
760+ testCases := []struct {
761+ name string
762+ opts * options.ClientBulkWriteOptionsBuilder
763+ want bool
764+ }{
765+ {
766+ name : "unacknowledged" ,
767+ opts : options .ClientBulkWrite ().SetWriteConcern (writeconcern .Unacknowledged ()).SetOrdered (false ),
768+ want : false ,
769+ },
770+ {
771+ name : "acknowledged" ,
772+ want : true ,
773+ },
774+ }
775+ for _ , tc := range testCases {
776+ tc := tc
777+
778+ mt .Run (tc .name , func (mt * mtest.T ) {
779+ mt .Parallel ()
780+
781+ var models * mongo.ClientWriteModels
782+
783+ insertOneModel := mongo .NewClientInsertOneModel ().SetDocument (bson.D {{"x" , 1 }})
784+ models = (& mongo.ClientWriteModels {}).AppendInsertOne ("foo" , "bar" , insertOneModel )
785+ res , err := mt .Client .BulkWrite (context .Background (), models , tc .opts )
786+ require .NoError (mt , err , "BulkWrite error: %v" , err )
787+ require .NotNil (mt , res , "expected a ClientBulkWriteResult" )
788+ assert .Equal (mt , res .Acknowledged , tc .want , "expected Acknowledged: %v, got: %v" , tc .want , res .Acknowledged )
789+ })
790+ }
791+ })
721792}
722793
723794func TestClient_BSONOptions (t * testing.T ) {
0 commit comments