当前位置:网站首页>ThinkPHP 6 使用 mongoDB
ThinkPHP 6 使用 mongoDB
2022-06-29 08:17:00 【amateur12】
在config/database.php添加mongoDB数据库配置信息:
// 更多的数据库配置信息
'mongodb'=>[
// 数据库类型
'type' => 'mongo',
// 服务器地址
'hostname' => '127.0.0.1',
// 数据库名
'database' => 'test',
// 用户名
'username' => '',
// 密码
'password' => '',
// 端口
'hostport' => '27017',
// 数据库连接参数
'params' => [],
// 数据库调试模式
'debug' => env('database.debug', true),
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 监听SQL
'trigger_sql' => true,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 是否严格检查字段是否存在
'fields_strict' => true,
// 是否需要断线重连
'break_reconnect' => false,
// 字段缓存路径
'schema_cache_path' => app()->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR,
]数据存入和读取的代码:
Db::connect('mongodb')
->table('one')
->insert(['name'=>123,'age'=>18]);
$res = Db::connect('mongodb')
->table('one')
->select();
dd($res);效果:

补充一点mongoDB的知识:
mongoDB使用场景:
实时读取,对速度有要求,读取快
数据量大,并且数据保存价值不大,比如说文章的评论,尽管有数据持久化,但仍有丢失风险
不要求使用事务,不支持事务
mongoDB使用案例:
京东,存储商品信息,和关注功能.
赶集网,记录pv浏览计数
奇虎360,每天接受200亿次的查询
百度云,存储500亿条关于文件源信息的记录.
CERN粒子物理研究所,存储大型强子对撞机的数据
mongoDB和Redis的区别:
内存管理机制:Redis数据全部存储在内存,定期写入磁盘,当内存不够是,可以选择指定的LRU算法删除数据。Mongodb数据存在内存上,由Linux系统mmap实现,当内存不够时,只将热点数据放入内存,其他数据存在磁盘。
数据结构:Redis支持多种数据结构,包括Hash、set、list等。Mongodb支持比较单一,但支持丰富的数据表达,索引,最类似于关系型数据库,支持的查询语言比较丰富。
边栏推荐
- 2022第六季完美童模 清远赛区 海选赛圆满落幕
- 《乔布斯传》英文原著重点词汇笔记(七)【 chapter five】
- 15 things to learn in a year of internship in famous enterprises, so you can avoid detours.
- Application of mediastreamer2 and GStreamer in embedded field
- Set up Jenkins environment and automatically associate packaged project jars for automatic release
- 十大券商账号开户安全吗?是靠谱的吗?
- Feature selection: maximum information coefficient (MIC) [used to measure the degree of correlation between two variables X and y, linear or nonlinear strength, commonly used for feature selection of
- Huawei equipment is configured with medium-sized network WLAN basic services
- [microservices openfeign] timeout of openfeign
- P4769-[noi2018] bubble sort [combinatorics, tree array]
猜你喜欢

2022春夏系列 KOREANO ESSENTIAL重塑时装生命力
![Speech synthesis: overview [generation task of unequal length sequence relation modeling]](/img/13/bd9def50f0efde49b622d139f63a83.png)
Speech synthesis: overview [generation task of unequal length sequence relation modeling]

Memoirs of actual combat: breaking the border from webshell

The return values of hostname -f and uname -n may be different

VMware vcenter/esxi series vulnerability summary

x86和x64的区别

Batch processing of experimental contact angle data matlab analysis

Typescript variable declaration - type assertion

Some "non-technical" Thoughts on distributed digital identity

2022第六季完美童模 海口赛区 选拔赛圆满落幕
随机推荐
Paddlenlp general information extraction model: UIE [information extraction {entity relationship extraction, Chinese word segmentation, accurate entity markers, emotion analysis, etc.}, text error cor
ThreadLocal thread variable
2022年7月系统集成项目管理工程师认证招生简章
(III) encoder self attention mask
名企实习一年要学会的15件事,这样你就省的走弯路了。
Wallpaper applet source code double ended wechat Tiktok applet
(pytorch进阶之路三)encoder self attention mask
51单片机中断与定时器计数器,基于普中科技HC6800-ESV2.0
VMware vcenter/esxi series vulnerability summary
Self attention mechanism
批量处理实验接触角数据-MATLAB分析
闭关修炼(二十四)浅入了解跨域问题
实战回忆录:从Webshell开始突破边界
Chengtong network disk imitation blue playing network disk source code with video tutorial
PaddleNLP通用信息抽取模型:UIE【信息抽取{实体关系抽取、中文分词、精准实体标。情感分析等}、文本纠错、问答系统、闲聊机器人、定制训练】
Differences between x86 and x64
Matlab 用法
【最全】PS各个版本下载安装及小试牛刀教程(PhotoShop CS3 ~~ PhotoShop 2022)
NP3 格式化输出(一)
2022第六季完美童模 海口赛区 选拔赛圆满落幕