Browse Source

test/busi/utils.go updated from example

pull/273/head
yedf2 4 years ago
parent
commit
716c20526f
  1. 6
      test/busi/utils.go

6
test/busi/utils.go

@ -147,8 +147,10 @@ func MongoGet() *mongo.Client {
mongoOnce.Do(func() {
uri := fmt.Sprintf("mongodb://%s:27017/?retryWrites=false", StoreHost)
ctx := context.Background()
logger.Infof("connecting to mongo: %s", uri)
client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri))
dtmimp.E2P(err)
logger.Infof("connected to mongo: %s", uri)
mongoc = client
})
return mongoc
@ -167,9 +169,9 @@ func SetRedisBothAccount(amountA int, ammountB int) {
func SetMongoBothAccount(amountA int, amountB int) {
mc := MongoGet()
col := mc.Database("dtm_busi").Collection("user_account")
_, err := col.InsertOne(context.Background(), bson.D{{Key: "user_id", Value: TransOutUID}, {Key: "balance", Value: amountA}})
_, err := col.ReplaceOne(context.Background(), bson.D{{Key: "user_id", Value: TransOutUID}}, bson.D{{Key: "user_id", Value: TransOutUID}, {Key: "balance", Value: amountA}}, options.Replace().SetUpsert(true))
dtmimp.E2P(err)
_, err = col.InsertOne(context.Background(), bson.D{{Key: "user_id", Value: TransInUID}, {Key: "balance", Value: amountB}})
_, err = col.ReplaceOne(context.Background(), bson.D{{Key: "user_id", Value: TransInUID}}, bson.D{{Key: "user_id", Value: TransInUID}, {Key: "balance", Value: amountB}}, options.Replace().SetUpsert(true))
dtmimp.E2P(err)
}

Loading…
Cancel
Save