mongodb
简介
提供mongodb数据库服务,根据配置文件自动开启mongodb服务。
依赖pkg.mongoc和pkg.cfg,是对pkg.mongoc的进一步封装,与pkg.cfg配合使用。
mongodb配置文件格式如下 :
{
"mongoc_cfg" :
{
"thread_num" : 2,
},
"mongo_dbs" :
{
"sample01" : {
"address" : {
"host" : "localhost",
"port" : "27017",
"db" : "dba_mongodb_sample01",
},
"auth" : {},
},
"sample02" : {
"address" : {
"host" : "localhost",
"port" : "27017",
"db" : "dba_mongodb_sample02",
},
"auth" : {},
},
},
"mongo_collections" : {
"sample01/account" : {
"name" : "primary",
"runtime_holder" : "index",
},
"sample02/user" : {
"name" : "primary",
"runtime_holder" : "index",
},
}
}
组件接口
mongodb.gs
函数原型 | 函数作用 |
---|---|
void start() | 根据cfg配置信息启动mongodb服务,创建db,并建立客户端连接 |
object new_client(map address, map auth, map collections) | 创建一个客户端连接 |
void name_client(string name, object client) | 给连接取个名字 |
parallel object find_client(string name) | 根据名字找到连接 |
void add_dbs(map mongo_dbs) | 根据配置信息增加db库 |
void add_collections(map mongo_collections) | 根据配置信息增加集合 |
parallel map get_table_info(string path) | 根据路径获取表信息 |
parallel mixed derive_data_for_table(string path, mixed primary_value, map data) | 根据表名(路径),将映射类型的数据转换为数据库中的记录 |
parallel array read_group(string path, map condition = , array fields = nil) | 读取指定表的数据 |
mongo_client.gs
函数原型 | 函数作用 |
---|---|
void start(map address, map auth, map collections) | 启动mongodb服务 |
void restart() | 重启mongodb服务 |
parallel object get_coll(string name) | 获取集合 |
void setup_index() | 初始化各个表的索引 |
object create_or_get_collection(string name) | 创建或获得指定collection |