package main import ( "context" "fmt" "github.com/qiniu/qmgo" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo/readpref" ) type User struct { NftpId string `bson:"nftp_id"` Id string `bson:"id"` UserName string `bson:"user_name"` Password string `bson:"password"` Salt string `bson:"salt"` Icon string `bson:"icon"` Type int `bson:"type"` PhoneNumber string `bson:"phone_number"` Email string `bson:"email"` CreateTime int64 `bson:"create_time"` Description string `bson:"description"` UpdateTime int64 `bson:"update_time"` } func main() { var maxPoolSize uint64 = 4096 ctx := context.Background() url := "mongodb://192.168.1.7:27017/?connect=direct&authSource=test" client, _ := qmgo.NewClient(ctx, &qmgo.Config{ Uri: url, ReadPreference: &qmgo.ReadPref{ MaxStalenessMS: 90000, Mode: readpref.SecondaryPreferredMode, }, MaxPoolSize: &maxPoolSize, }) coll := client.Database("test").Collection("user") var user User err := coll.Find(ctx, bson.M{"id": "004"}).One(&user) if err != nil { fmt.Println(err.Error()) } fmt.Println(user) }