当前位置:网站首页>Using mongodb in laravel
Using mongodb in laravel
2022-07-02 01:45:00 【larance】
Installation of components
composer require jenssegers/mongodbRegistration 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();
}
}边栏推荐
- Cross domain? Homology? Understand what is cross domain at once
- Tencent cloud techo youth dream campus trip into Wuhan University
- Edge computing accelerates live video scenes: clearer, smoother, and more real-time
- 遷移雲計算工作負載的四個基本策略
- 微信小程序中使用tabBar
- [IVX junior engineer training course 10 papers] 06 database and services
- [Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing
- Have you stepped on the nine common pits in the e-commerce system?
- Implementation principle of city selector component
- Architecture evolution from MVC to DDD
猜你喜欢

跨域?同源?一次搞懂什么是跨域

三分钟学会基础k线图知识

【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享
![[rust web rokcet Series 2] connect the database and add, delete, modify and check curd](/img/23/cfa13ad30e45ef7cdda690775964a7.jpg)
[rust web rokcet Series 2] connect the database and add, delete, modify and check curd

城市选择器组件实现原理

matlab 使用 audiorecorder、recordblocking录制声音,play 播放声音,audiowrite 保存声音

Pyldavis installation and use | attributeerror: module 'pyldavis' has no attribute' gensim '| visual results are exported as separate web pages

Réseau neuronal convolutif (y compris le Code et l'illustration correspondante)

机器学习基本概念

How can I batch produce the same title for the video?
随机推荐
Matlab uses resample to complete resampling
人工智能在网络安全中的作用
Matlab uses audiorecorder and recordblocking to record sound, play to play sound, and audiobook to save sound
Six lessons to be learned for the successful implementation of edge coding
电子协会 C语言 1级 33 、奇偶数判断
[Floyd] post disaster reconstruction
[IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me
自动浏览拼多多商品
Three core problems of concurrent programming
[rust web rokcet Series 2] connect the database and add, delete, modify and check curd
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
Game thinking 15: thinking about the whole region and sub region Services
Ubuntu20.04 PostgreSQL 14 installation configuration record
2022年6月国产数据库大事记
Memorabilia of domestic database in June 2022
[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing
6-3漏洞利用-SSH环境搭建
Data visualization in medical and healthcare applications
How to use a product to promote "brand thrill"?
1218 square or round