当前位置:网站首页>Using mongodb in laravel
Using mongodb in laravel
2022-07-02 01:45:00 【larance】
Installation of components
composer require jenssegers/mongodb
Registration service , stay config/app.php
Jenssegers\Mongodb\MongodbServiceProvider::class,
Modify the database configuration file config/database.php
add to MongoDB Database information for :
'mongodb' => [
'driver' => 'mongodb',
'host' => 'localhost',
'port' => 27017,
'database' => 'mydb',
'username' => '',
'password' => '',
],
'default' => env('DB_CONNECTION', 'mysql'),
Change to :
'default' => env('DB_CONNECTION', 'mongodb'),
// Build a UserController.php controller
php artisan make:controller UserController
Reference code :
use DB; // Reference database
class MongoController extends Controller{
public function Index(){
// insert data
$ret = DB::insert('users')
->insert([
'name' => 'tom',
'age' => 118
]);
// Get a single piece of data
$res = DB::collection('users')->find('6209f085fb45615be77fb164');
// Get multiple pieces of data
$res = DB::collection('users')->get()->toArray();
// Get _id
var_dump((string)$res[0]['_id']);
// Query multiple data
$res = DB::collection('users')->where('age', 118)->get()->toArray();
// to update
$res = DB::collection('users')->where('age', 118)->update(['name'=>"larance"]);
// Delete
$res = DB::collection('users')->where('age', 118)->delete();
}
}
边栏推荐
- 技术大佬准备就绪,话题C位由你决定
- Fastadmin controls the length of fields in the table
- Learn C language from scratch day 025 (maze)
- Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
- Experimental reproduction of variable image compression with a scale hyperprior
- Volume compression, decompression
- Android: how can golden nine and silver ten squeeze into the first-line big factories from small and medium-sized enterprises? The depth of interview questions in large factories
- Study note 2 -- definition and value of high-precision map
- new和malloc的区别
- There are spaces in the for loop variable in the shell -- IFS variable
猜你喜欢
[Floyd] post disaster reconstruction
[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing
Three core problems of concurrent programming
Matlab uses audiorecorder and recordblocking to record sound, play to play sound, and audiobook to save sound
Raspberry pie 4B learning notes - IO communication (1-wire)
6-3 vulnerability exploitation SSH environment construction
游戏思考15:全区全服和分区分服的思考
[rust web rokcet Series 2] connect the database and add, delete, modify and check curd
6-3漏洞利用-SSH环境搭建
Learn about servlets
随机推荐
MPLS experiment operation
Laravel artisan 常用命令
[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing
Data visualization in medical and healthcare applications
Android high frequency network interview topic must know and be able to compare Android development environment
new和malloc的区别
There are spaces in the for loop variable in the shell -- IFS variable
np.where 和 torch.where 用法
Brief description of grafana of # yyds dry goods inventory # Prometheus
Liteos learning - first knowledge of development environment
How can the tsingsee Qingxi platform play multiple videos at the same time on the same node?
Memorabilia of domestic database in June 2022
Quatre stratégies de base pour migrer la charge de travail de l'informatique en nuage
Introduction to ffmpeg Lib
Since I understand the idea of dynamic planning, I have opened the door to a new world
Finally got byte offer, 25-year-old inexperienced experience in software testing, to share with you
This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable
[image enhancement] vascular image enhancement based on frangi filter with matlab code
企业应该选择无服务器计算吗?
Another programmer "deleted the library and ran away", deleted the code of the retail platform, and was sentenced to 10 months