Roc 2 月之前
父节点
当前提交
c1660f436f
共有 1 个文件被更改,包括 4 次插入1 次删除
  1. 4 1
      utils/mgodb/mgo_config.go

+ 4 - 1
utils/mgodb/mgo_config.go

@@ -8,6 +8,7 @@ import (
 	"go.mongodb.org/mongo-driver/bson"
 	"go.mongodb.org/mongo-driver/event"
 	mgoptions "go.mongodb.org/mongo-driver/mongo/options"
+	"go.mongodb.org/mongo-driver/mongo/writeconcern"
 	"sync"
 )
 
@@ -78,7 +79,9 @@ func MgoNewClient(mgoConfig MgoConfig) *qmgo.Client {
 	}
 
 	// 创建options
-	ops := options.ClientOptions{ClientOptions: &mgoptions.ClientOptions{}}
+	ops := options.ClientOptions{ClientOptions: &mgoptions.ClientOptions{
+		WriteConcern: &writeconcern.WriteConcern{W: "majority"},
+	}}
 	ops.SetMonitor(cmdMonitor)
 
 	ctx := context.Background()