Go to file
2022-02-23 16:59:45 +08:00
builder first commit 2022-02-23 16:59:45 +08:00
.gitignore first commit 2022-02-23 16:59:45 +08:00
aggregate_scope_test.go first commit 2022-02-23 16:59:45 +08:00
aggregate_scope.go first commit 2022-02-23 16:59:45 +08:00
autogen_model_field_mdbc.go first commit 2022-02-23 16:59:45 +08:00
autogen_model_mdbc.go first commit 2022-02-23 16:59:45 +08:00
breaker.go first commit 2022-02-23 16:59:45 +08:00
bulk_write_scope_test.go first commit 2022-02-23 16:59:45 +08:00
bulk_write_scope.go first commit 2022-02-23 16:59:45 +08:00
codec.go first commit 2022-02-23 16:59:45 +08:00
config.go first commit 2022-02-23 16:59:45 +08:00
convert.go first commit 2022-02-23 16:59:45 +08:00
count_scope_test.go first commit 2022-02-23 16:59:45 +08:00
count_scope.go first commit 2022-02-23 16:59:45 +08:00
debugger.go first commit 2022-02-23 16:59:45 +08:00
define.go first commit 2022-02-23 16:59:45 +08:00
delete_scope_test.go first commit 2022-02-23 16:59:45 +08:00
delete_scope.go first commit 2022-02-23 16:59:45 +08:00
distinct_scope_test.go first commit 2022-02-23 16:59:45 +08:00
distinct_scope.go first commit 2022-02-23 16:59:45 +08:00
drop_scope.go first commit 2022-02-23 16:59:45 +08:00
find_one_scope_test.go first commit 2022-02-23 16:59:45 +08:00
find_one_scope.go first commit 2022-02-23 16:59:45 +08:00
find_scope_test.go first commit 2022-02-23 16:59:45 +08:00
find_scope.go first commit 2022-02-23 16:59:45 +08:00
gen.sh first commit 2022-02-23 16:59:45 +08:00
go.mod first commit 2022-02-23 16:59:45 +08:00
hook.go first commit 2022-02-23 16:59:45 +08:00
icon.png first commit 2022-02-23 16:59:45 +08:00
index_scope_test.go first commit 2022-02-23 16:59:45 +08:00
index_scope_v2.go first commit 2022-02-23 16:59:45 +08:00
index_scope.go first commit 2022-02-23 16:59:45 +08:00
insert_scope_test.go first commit 2022-02-23 16:59:45 +08:00
insert_scope.go first commit 2022-02-23 16:59:45 +08:00
mdbc.pb.go first commit 2022-02-23 16:59:45 +08:00
mdbc.proto first commit 2022-02-23 16:59:45 +08:00
mongo.go first commit 2022-02-23 16:59:45 +08:00
new.go first commit 2022-02-23 16:59:45 +08:00
README.md first commit 2022-02-23 16:59:45 +08:00
scope_test.go first commit 2022-02-23 16:59:45 +08:00
scope.go first commit 2022-02-23 16:59:45 +08:00
transaction_scope_hook.go first commit 2022-02-23 16:59:45 +08:00
transaction_scope_test.go first commit 2022-02-23 16:59:45 +08:00
transaction_scope_v2.go first commit 2022-02-23 16:59:45 +08:00
transaction_scope.go first commit 2022-02-23 16:59:45 +08:00
update_module.sh first commit 2022-02-23 16:59:45 +08:00
update_scope_test.go first commit 2022-02-23 16:59:45 +08:00
update_scope.go first commit 2022-02-23 16:59:45 +08:00
utils.go first commit 2022-02-23 16:59:45 +08:00

MDBC

快速开始

初始化mongo数据库连接

client, err := mongodb.ConnInit("mongodb://admin:admin@10.0.0.135:27017/admin")
if err != nil {
    logrus.Fatalf("get err: %+v", err)
}
mdbc.InitDB(client.Database("mdbc"))

声明 model

var m = mdbc.NewModel(&ModelSchedTask{})

然后就可以使用 m 进行链式操作

注册全局对象

可以将model注册成一个全局变量

type WsConnectRecordScope struct {
    *mdbc.Scope
}

var WsConnectRecord *WsConnectRecordScope

func NewWsConnectRecord() {
    WsConnectRecord = new(WsConnectRecordScope)
    WsConnectRecord.Scope = mdbc.NewModel(&model.ModelWsConnectRecord{})
}

使用:

func beforeRemoveWs(ctx context.Context, recordID, key string) {
    if WsConnectRecord == nil {
        NewWsConnectRecord()
    }
    tm := time.Now().UnixNano() / 1e6
    if message_common.GetEtcdWatcher().RemoveWatch(key) {
        // 已经移除 变更最近的一条消息
        err := WsConnectRecord.SetContext(ctx).FindOne().SetFilter(bson.M{
            model.ModelWsConnectRecordField_Id.DbFieldName: recordID,
        }).Update(bson.M{
            "$set": bson.M{
                model.ModelWsConnectRecordField_LogoutAt.DbFieldName: tm,
            },
        })
        if err != nil {
            log.Errorf("update ws conn record err: %+v", err)
            common.Logger.Error(ctx, "WsConn", log2.String("error", err.Error()))
        }
    }
}