Download the PHP package phper666/mongo-db without Composer

On this page you can find all versions of the php package phper666/mongo-db. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mongo-db

默认使用mongodb提供的库来封装,官方git地址:https://github.com/mongodb/mongo-php-library

1、支持类似mysql orm的一些操作

2、支持迁移文件

3、只支持hyperf框架,由于swoole协程不支持mongodb,所以所有的方法都采用task进程来实现,该包已经封装好所有的方法都会投递到task进程进行操作,task进程建议开启多一点

4、该包默认使用了连接池

注意:

1、v1.0+版本只会维护不增加功能
2、开启v2.0分支,跟1.0有很大区别,因为hyperf采用了laravel的orm,所以我会参考laravel-mongodb来封装
3、使用v1.0+时,如果你开一百多个task进程处理,你的宿主机内存不大时,并发请求多,导致内存没有被释放,这时候你的宿主机可能会down机,所以建议开启swoole的task配置,task_max_request=2,这个配置的意思是task进程处理两次请求后会自动kill这个task进程,重新拉起一个新的task进程,这样就不会导致你的宿主机内存过大而导致服务器down机

v1.0+有个大bug,目前无法解决,实际是目前操作mongodb都没有丢到task处理,需要hyperf2.0才能解决,具体情况这个issue[https://github.com/hyperf/hyperf/issues/1798]

这个bug目前我们在项目中如何解决,有两种方法:
1、在model里面新增一个getMethod方法,这个方法申请要丢到task处理

2、在你使用Test这个模型的方法直接申明丢到Task处理,这个方式不是万能的,因为Task不能处理一些需要在协程下处理的东西,例如co或者协程http,所以只能是第一种和第二种方法结合使用

使用

1、拉取包

2、发布配置

3、配置介绍

4、生成迁移文件

上面的命令会自动生成一个迁移文件,会生成一个文件到配置文件指定的迁移目录中

5、迁移文件例子

6、迁移命令

上面这个命令会迁移你所有生成的文件,迁移文件路径在配置文件里面配置

7、开发使用

1、上面能像orm一样能进行迁移了,解决了升级的问题,下面我们来说一下开发时候怎么使用
2、在你的项目里面新建一个目录,该目录叫mongo(自行命名,类似orm的model)
3、比如我现在项目里面有一个库,叫test,test里面有两个collection,名字为co1,co2(你把它当成mysql的表一样)
4、我在mongo目录新建两个文件,叫Co1Mongo和Co2Mongo,都继承\Phper666\MongoDb\MongoDb

5、查询co1中的一条数据

6、支持有多种方法,详细你可以到Phper666\MongoDb\MongoDb查看,或者你可以去看官方的php-mongodb文档,https://docs.mongodb.com/php-library/v1.5/reference/method/MongoDBCollection-createIndexes/

8、结束

如果你有使用的问题或者建议,欢迎你提一个isset,由于太匆忙,等我开发完现在的项目,我会重新优化和迭代这个包,如果开发中有遇到问题或者有更好的写法,我会迭代到这个包这里。

9、注意

如果你使用的是mongodb默认生成_id,那么更新和删除我默认已经帮你使用MongoDB\BSON\ObjectId进行了转换,所以你无需再转换,你直接把_id对应的字符串传进去就好了,比如要根据_id获取某条数据,$filter=['_id' => 'xxxxxx']即可。获取数据时,我也默认帮你把_id转成了字符串

10、遇到问题

1、因为我使用了hyperf框架,所以基本都是单例模式。我model里面使用\Phper666\MongoDb\MongoDb 的setCollectionName方法来切换表时,必须处理完逻辑后然后再切回原始的collectionName,否则你查询的会是你切换的表


All versions of mongo-db with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
psr/container Version ^1.0
mongodb/mongodb Version ^1.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package phper666/mongo-db contains the following files

Loading the files please wait ....