小编给大家分享一下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=newcls_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);

以上是mongodb分库的方法的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!