|
|
|
@ -145,7 +145,7 @@ var ( |
|
|
|
// MongoGet get mongo client
|
|
|
|
func MongoGet() *mongo.Client { |
|
|
|
mongoOnce.Do(func() { |
|
|
|
uri := fmt.Sprintf("mongodb://%s:27017/?retryWrites=false", StoreHost) |
|
|
|
uri := fmt.Sprintf("mongodb://%s:27017/?retryWrites=false&directConnection=true", StoreHost) |
|
|
|
ctx := context.Background() |
|
|
|
logger.Infof("connecting to mongo: %s", uri) |
|
|
|
client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri)) |
|
|
|
@ -169,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.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)) |
|
|
|
_, err := col.ReplaceOne(context.Background(), bson.D{{Key: "user_id", Value: TransOutUID}}, bson.D{{Key: "user_id", Value: TransOutUID}, {Key: "balance", Value: float64(amountA)}}, options.Replace().SetUpsert(true)) |
|
|
|
dtmimp.E2P(err) |
|
|
|
_, 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)) |
|
|
|
_, err = col.ReplaceOne(context.Background(), bson.D{{Key: "user_id", Value: TransInUID}}, bson.D{{Key: "user_id", Value: TransInUID}, {Key: "balance", Value: float64(amountB)}}, options.Replace().SetUpsert(true)) |
|
|
|
dtmimp.E2P(err) |
|
|
|
|
|
|
|
} |
|
|
|
|