45 lines
870 B
Go
45 lines
870 B
Go
|
package mongo
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/qiniu/qmgo"
|
||
|
)
|
||
|
|
||
|
type UserIdMap struct {
|
||
|
Seq int64 `json:"seq" bson:"_id"` //用户业务id序列号
|
||
|
UserId int64 `json:"user_id" bson:"user_id"` //映射后用户业务id序列号
|
||
|
}
|
||
|
|
||
|
type Mongo struct {
|
||
|
clientMix *qmgo.Client
|
||
|
}
|
||
|
|
||
|
func NewMongo() (mongo *Mongo, err error) {
|
||
|
mongo = new(Mongo)
|
||
|
|
||
|
mongo.clientMix, err = NewMongoClient()
|
||
|
if err != nil {
|
||
|
fmt.Printf("NewMongoClient fail, cfg: %v, err: %v", nil, err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
return
|
||
|
}
|
||
|
|
||
|
const (
|
||
|
DBUserIdSeq = "user_id_seq"
|
||
|
COLUserIdMap = "user_id_map"
|
||
|
)
|
||
|
|
||
|
func (m *Mongo) getColUserIdMap() *qmgo.Collection {
|
||
|
return m.clientMix.Database(DBUserIdSeq).Collection(COLUserIdMap)
|
||
|
}
|
||
|
|
||
|
func (m *Mongo) CreateBatch(ctx context.Context, userIdSeqs []*UserIdMap) error {
|
||
|
col := m.getColUserIdMap()
|
||
|
_, err := col.InsertMany(ctx, userIdSeqs)
|
||
|
return err
|
||
|
}
|