ITPub博客

首页 > IT职业 > IT职场 > mongodb怎样分库

mongodb怎样分库

IT职场 作者:petterchx 时间:2021-09-11 10:24:43 0 删除 编辑

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入门教程,欢迎在线学习!

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4606/viewspace-2835039/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-10-24

  • 博文量
    131
  • 访问量
    30132