mongodb怎样分库

312次阅读
没有评论

mongodb怎样分库

1、建立一个新的mongodb库。

2、把当前的mongodb集合改为比如 log_data为log_data_201904062230。

3、把log_data_201904062230备份到新库中。

4、在获取数据的地方再连接新库的log_data_201904062230集合展示数据。

代码示例如下:

$where = array();
if( $product_id )
{
    $where['lq_product_id'] = $product_id;
}
if( $qrcode )
{
    $where['lq_qrcode'] = $qrcode;
   //$where['lq_qrcode'] ="75906.DRMWH.A.13_50.N";
}
if( $lq_user)
{
   $where['lq_user'] = $lq_user;
}
$page_list_num = 100;
$cls_log = cls_app:: get_cls( 'log' ); 
$cls_log->set_collection( 'log_data' );
$list = $cls_log->get_list( $page, $page_list_num, $where, array( 'lq_time'=> -1 ) );
//去历史里拉数据
$cls_log_his = new cls_log ( 'bullfrog_history' );
$cls_log_his -> set_db( 'log' );
$cls_log_his -> set_collection( 'log_data_201904062230' );
$list_his = $cls_log_his->get_list( $page, $page_list_num, $where, array( 'lq_time'=> -1 ) );
$list_all = array_merge( $list, $list_his );

python学习网,大量的免费MongoDB入门教程,欢迎在线学习!

神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:MongoDB2022-12-06发表,共计987字。
新手QQ群:570568346,欢迎进群讨论 Python51学习