[PHP]新版的mongodb扩展安装和使用
发布时间:2021-05-21 06:53:34 所属栏目:大数据 来源: https://www.jb51.cc
导读:旧版的mongo扩展已经不推荐使用了,在PHP7以上一般是安装和使用新版的mongodb扩展 ubuntu下 apt-get install PHP-mongodb 例如下面的代码进行了查询和插入集合操作 ? PHP class DocModel{ public $mongoManger = null ; $dbName ='coms' public function __c
旧版的mongo扩展已经不推荐使用了,在PHP7以上一般是安装和使用新版的mongodb扩展 ubuntu下 apt-get install PHP-mongodb 例如下面的代码进行了查询和插入集合操作 <?PHP class DocModel{ public $mongoManger=null; $dbName='coms'public function __construct(){ // 连接到mongodb $this->mongoManger = new MongoDBDriverManager("mongodb://127.0.0.1:27017"); } 添加文档模型 function addModel($isDraft=false){ $params=[]; $params['modelID']='basic_news'; $params['name']='基础新闻'$params['parentID']='root'$params['modelXML']="<?xml version="1.0" encoding="utf-8"?>rn<model>rnt <fields>rnt <field label="标题" name="title" type="string" widget="title" required="1" maxLength="60" minLength="1" esAnalyzed="analyzed" esAddNoAnalyzed="yes" >rntt<widgetParams>rnttt<param name="marks" value="5,13.5,40"/>rntt</widgetParams>rntt<validation>rnttt<rule type="maxZhLength" value="40" msgZh="标题长度不能超过40个汉字长度" />rntt</validation>rnt</field>rntt </fields>rn <layout>rnt<fieldset name="basic" legend="基本信息">rntt<field name="title" width="12"/>rnt</fieldset>trn </layout>rn</model>"$params['isTest']='0'$params['desc']='shihan添加'$params['auditFeedback']=''$params['status']='1'; $params['audited']='1'$collect=$isDraft ? '.modelDraft':'model'; $bulk = new MongoDBDriverBulkWrite(); $sets= ['$set' => $params]; $bulk->update(['modelID' => $params['modelID']],$sets,['multi' => false,'upsert' => true]); $this->mongoManger->executeBulkWrite($this->dbName.$collect,1)">$bulk文档模型列表 function listModel($filter = []; $options =$query = new MongoDBDriverQuery($filter,1)">$options); $cursor = $this->mongoManger->executeQuery($query); foreach ($cursor as $document) { var_dump(); } } 获取文档模型详情 function getModel($filter = ['modelID'=>$params['modelID']]; ); } } } $docModel= DocModel(); $docModel->getModel(true); ? (编辑:北几岛) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读