- 浏览: 58764 次
- 性别:
- 来自: 广州
文章分类
最新评论
前提:使用Eloquent访问mongodb
1、新增
2、修改
3、删除
4、查询
5、搜索
6、聚合
class ResourceModel extends Eloquent { protected $collection = 'resource'; protected $connection = 'mongodb'; }
1、新增
class ResourceService extends BaseService { private $collection; private $resourceModel; public function __construct() { parent::__construct(); $connection =DB::connection('mongodb'); $this->collection = $connection->collection('resource'); $this->resourceModel = new ResourceModel(); } public function add($array){ if(!isset($array['rms_uuid']) || !$array['rms_uuid']){ throw new \Exception('缺少资源ID', 10022); } $this->collection->insert($array); return $this->collection->where('rms_uuid', $array['rms_uuid'])->get(); } ....... ....... }
2、修改
class ResourceService extends BaseService { ....... ....... public function modify($uuid, $fields) { $res = $this->getByUuid($uuid); if(!$res){ throw new \Exception('资源不存在', 20027); } foreach ($fields as $key=>$value) { $res->$key = $value; } $res->modifiedtime = time(); $res->save(); return $res; } ....... ....... }
3、删除
class ResourceService extends BaseService { ....... ....... public function remove($uuid) { $res = $this->getByUuid($uuid); if(!$res){ throw new \Exception('资源不存在', 20027); } $res->delete(); } ....... ....... }
4、查询
class ResourceService extends BaseService { ....... ....... public function getByUuid($uuid) { return ResourceModel::where('rms_uuid', $uuid)->first(); } ....... ....... }
5、搜索
class ResourceService extends BaseService { ....... ....... public function search($conditions=[], $skip = 0, $limit = 200) { $result = [ 'count' => 0, 'list' => [] ]; $tcollection = $this->collection; $resourceTypeFieldService = new ResourceTypeFieldService(); if($conditions && is_array($conditions)) { foreach ($conditions as &$condition) { if(!isset($condition['field']) || !isset($condition['operator']) || !isset($condition['value'] )){ throw new \Exception('无效的查询表达式', 20025); } if(is_int($condition['field'])){ $fieldId = $condition['field']; $field = $resourceTypeFieldService->get($fieldId); if (!$field) { throw new \Exception('无效的查询字段', 20026); } $condition['field'] = $field['field']; } $field = $condition['field']; $operator = $condition['operator']; $value = $condition['value']; switch($condition['operator']){ case '>': case '=': case '<': $tcollection = $tcollection->where($field, $operator, $value); break; case 'exists': $tcollection = $tcollection->where($field, $operator, true); break; case 'all': if(!is_array($value)){ throw new \Exception('all操作符只支持数组对象', 20027); } $tcollection = $tcollection->where($field, $operator, $value); break; case 'size': if(!is_int($value)){ throw new \Exception('size操作符只支持整数', 20028); } $tcollection = $tcollection->where($field, $operator, $value); break; case 'regex': $value = new Regex($value, ''); $tcollection = $tcollection->where($field, $operator, $value); break; case 'type': if(!is_int($value)){ throw new \Exception('type操作符只支持整数', 20029); } $tcollection = $tcollection->where($field, $operator, $value); break; case 'mod': if(!is_array($value)){ throw new \Exception('mod操作符只支持数组对象', 20031); } $tcollection = $tcollection->where($field, $operator, $value); break; case 'null': $tcollection = $tcollection->whereNull($field); break; case 'in': if(!is_array($value)){ throw new \Exception('in操作符只支持数组对象', 20032); } $tcollection = $tcollection->whereIn($field, $value); break; case 'between': if(!is_array($value) || sizeof($value) != 2){ throw new \Exception('in操作符只支持数组对象,且数组元素必须2个', 20033); } $tcollection = $tcollection->whereBetween($field, $value); break; default: throw new \Exception('无效的条件操作符:' . $condition['operator'], 20030); } } } $count = $tcollection->count(); if ($count == 0) { return $result; } $list = $tcollection->skip($skip)->take($limit)->get(); $result['count'] = $count; $result['list'] = $list; return $result; } ....... ....... }
6、聚合
发表评论
-
建立一个支持并发的Laravel任务模块
2020-09-30 10:17 434laravel/lumen的事件、任务调度等都是基于队列来实现 ... -
ElementUI上传组件在Lumen环境下跨域问题的解决
2020-08-25 11:10 841在后台的路由中间件中要增加跨域设置: namespace ... -
lumen集成结巴分词
2020-03-31 16:46 279常规的方法是通过compoer集成 composer re ... -
Lumen/laravel动态分库的实现
2019-07-04 10:39 758lumen默认支持多数据源,但如果系统存在多个结构相同的数据库 ... -
lumen5.5使用rabbitmq
2019-01-21 10:53 1076在composer.json中的require中增加以下语句 ... -
lumen使用mongodb
2019-01-09 16:16 16821. 安装mongodb扩展 执行sudo pecl in ... -
在lumen中开发和执行artisan命令行任务
2018-12-22 17:28 1851lumen是laravel的简化版,其中artisan部分删除 ... -
在lumen安装阿里云短信服务SDK
2018-12-12 12:15 8091、下载SDK:https://help.aliyun.com ... -
lumen日志权限冲突问题
2016-11-02 11:44 1721运行lumen项目一般使用nginx作为webserver,因 ... -
lumen中使用调度任务
2016-04-22 12:21 2971需要在crontab中增加一行 * * * * * php ... -
在lumen中使用smtp方式发送txt/plain邮件
2016-04-22 11:46 12411、安装邮件组件 修改composer.json,在re ... -
lumen下操作excel
2016-04-22 11:34 19851、安装excel组件 修改composer.json, ... -
lumen中使用redis队列
2016-04-22 11:18 18191、采用redis作为队列驱动 修改.env文件 QU ... -
lumen中安装及使用redis作为cache
2016-04-22 10:54 20771、安装redis模块 在compose.json的re ...
相关推荐
创建该代码库的目的是演示使用Lumen + MongoDB构建的功能齐全的REST API,包括CRUD操作,身份验证,路由,分页等。 它从大量借鉴由 。 有关如何与其他前端/后端一起使用的更多信息,请转到库。 希望本示例对您有所...
Laravel登录到数据库 自定义Laravel 5.6+日志通道处理程序,可以将日志事件存储到SQL或MongoDB数据库。 使用Laravel本机日志记录功能。 :warning_selector: 这个项目应该向下兼容,包括Laravel 5.6和PHP 7.1。 但是...
mongorestore -d lumen_lumen_dev /media/ceefour/passport/project_passport/lumen/mongodb/lumen_lumen_dev将Yago2s数据转换为MongoDB(不需要) 注意:您不需要这样做。 当您要从Yago2s重新生成MongoDB数据集时...
Lumen API 依靠 GoLang Gin Gonic Web 框架、MongoDB 和 AWS SES 进行邮件管理。入门生成 API 密钥如果您想发送邮件(用于用户帐户管理),lumen-api 使用 AWS SES,因此您应该获取。 从包含的.env.example文件模板...
Laravel开发-laravel-auditing-mongodb 审核您在Laravel/Lumen中雄辩模型的更改
社区讨论传送 Lumen学习交流群:1105120693(QQ)概览初步支持适应Laravel 7中新增的HttpClient客户端(已升级到Laravel 8) RESTful规范的路由定义和HTTP响应结构使用Laravel Api资源支持自定义业务操作应码以及...
Laravel开发-laravel-mongo 在Laravel和Lumen中使用MongoDB文档的便利库
Xenus是一个简单而优雅的MongoDB ODM。 它具有对事件的内置和跨框架支持( ) 它使您的模式可以通过文档的mutators ( )进行自我记录它包括更新,删除和插入文档( )的流利方法它支持通过高级语法( )嵌入它开箱...
Laravel开发-laravel-auditing-mongo-db 使用laravel和lumen with mongo db为您的模型保留更改历史记录
流明服务器 流明框架的后端服务 启动服务器 ... 服务器在端口8000上运行,... chuckrincon / lumen-config-discover nuwave /灯塔 mll-lab / laravel-graphql-playground tymon / jwt-auth darkaonline / swagger-lume
gazsp/雄辩的驾驶舱最后一起使用 Cockpit 和 Laravel Eloquent。 使用 。...Laravel TBC(可能和Lumen没什么区别)用法如果您在 Cockpit 中有一个名为“Events”的集合,则 Laravel 或 Lumen 中的模
使用Laravel / Lumen,Vue和MySQL 。 内容 指令 安装 克隆存储库 确保您使用的节点版本> = 14( nvm install 14 / nvm use 14 ) 安装节点模块( npm i ) 在过程中或在存储库根目录中的.env文件中,传递以下...
它基于PHP Lumen框架和MongoDB构建。 它是如何工作的? Gandalf允许您定义多个决策表并列出所有已做出的决策。 您可以将其用于反欺诈,风险管理以及任何其他决策目的。 产品特点 可自定义-可以自由设计所需的决策...
一个简单的带有node.js的MVC结构,对于那些具有Laravel / Lumen项目结构经验的人来说,构建RESTful API非常方便。 这也阻止了开发人员编写难以理解的,结构化的,难以维护的源代码spaghetti-code ,这是我刚开始使用...
:telescope: 我目前在Lumen Technologies India工作 :seedling: 我目前正在学习Angular7 +,ReactJS,VanillaJS,NodeJS,ExpressJS,MongodB :people_with_bunny_ears: 我正在寻找Web应用程序上的合作伙伴 :...