当前位置:网站首页>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();
}
}边栏推荐
- Edge computing accelerates live video scenes: clearer, smoother, and more real-time
- Réseau neuronal convolutif (y compris le Code et l'illustration correspondante)
- Implementation of Weibo system based on SSM
- D discard the virtual recovery method
- 并发编程的三大核心问题
- Learn basic K-line diagram knowledge in three minutes
- 2022年6月国产数据库大事记
- [disease detection] realize lung cancer detection system based on BP neural network, including GUI interface
- Learn about servlets
- 学习笔记24--多传感器后融合技术
猜你喜欢

matlab 使用 resample 完成重采样

It's already 30. Can you learn programming from scratch?

Basic concepts of machine learning

The role of artificial intelligence in network security

Matlab uses audioread and sound to read and play WAV files

Edge computing accelerates live video scenes: clearer, smoother, and more real-time

Number of palindromes in C language (leetcode)
![[image enhancement] vascular image enhancement based on frangi filter with matlab code](/img/b3/b4164fb7db8645f470180e352b5717.png)
[image enhancement] vascular image enhancement based on frangi filter with matlab code

TSINGSEE青犀平台如何实现同一节点同时播放多个视频?

The technology boss is ready, and the topic of position C is up to you
随机推荐
The difference between new and malloc
[IVX junior engineer training course 10 papers to get certificates] 03 events and guessing numbers games
6-2 vulnerability exploitation - inevitable problems of FTP
Matlab uses audioread and sound to read and play WAV files
Learning notes 25 - multi sensor front fusion technology
[IVX junior engineer training course 10 papers] 05 canvas and aircraft war game production
城市选择器组件实现原理
如何用一款产品推动「品牌的惊险一跃」?
D discard the virtual recovery method
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
Basic number theory -- Gauss elimination
Convolutional neural network (including code and corresponding diagram)
I Brief introduction of radio energy transmission technology
电商系统中常见的9大坑,你踩过没?
Makefile simple induction
并发编程的三大核心问题
Finally got byte offer, 25-year-old inexperienced experience in software testing, to share with you
Matlab uses resample to complete resampling
Experimental reproduction of variable image compression with a scale hyperprior
Luogu p1775 stone merger (weakened version)