Provides various official and user-released code examples for reference. You are welcome to exchange and learn. 123
Recently, I learned about NoSql and chose mongodb. I encountered some pitfalls when using mongodb. I would like to share my experience with you so that you can avoid repeated pitfalls.
1. Install mongodb
Go to the official website https://www.mongodb.org/to download the installation package for my yuminstallation.
2. install php-mongodb Extension
See https://blog.endaosi.com/archives/MongoDB-exera.html
3. configure access permissions and account passwords
See http://blog.sina.com.cn/s/blog_48f9c0840100ncsm.html
It is worth mentioning that the mongodb account can be relatively global, or you can add users to a single database. Only one permission can be written.
4. Use thinkphp
Configuration (config. php)
'MONGO_DB' => array(
'db_type' => 'mongo',
'db_host' => 'mini-server.endaosi.com',
'db_user' => 'endaosi',
'db_pwd' => 'aaaa123456',
'db_port' => '27017',
'db_name' => 'shcms',
)
Use, see http://document.thinkphp1.cn/manual_3_2.html#mongo
$model = M('\Think\Model\MongoModel:User','',MONGO_DB);
$result = $model -> add(['a'=>'abc','b'=>'123']);
$result = $model -> add(['email'=>'shellus@vip.qq.com');
dump($model -> count());
dump($model -> select());
So far, mongodb has been used in tp.
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB