定制 webiny/mongo 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

webiny/mongo

Composer 安装命令:

composer require webiny/mongo

包简介

Webiny Mongo Component

README 文档

README

Mongo Component is used for working with MongoDB database.

Install the component

The best way to install the component is using Composer.

composer require webiny/mongo

For additional versions of the package, visit the Packagist page.

Configuring Mongo service

The recommended way of using Mongo is by defining a Mongo service. Here is an example of defining a service:

Mongo:
    Services:
        Webiny:
            Class: \Webiny\Component\Mongo\Mongo
            Arguments:
                Uri: 127.0.0.1:27017
                UriOptions: []
                DriverOptions: []
                CollectionPrefix: 'MyDatabase_'
            Calls: 
                - [selectDatabase, [MyDatabase]]
    Driver: \Webiny\Component\Mongo\Bridge\MongoDb

Collection prefix will be automatically prepended for you to all database queries.

For more information see: mongodb/mongo-php-library

After you have defined your Mongo services (in most cases you will only need one, but you can have as many as you like), you can access your Mongo services by using MongoTrait:

class MyClass {
    use MongoTrait;

    public function test(){
        // MongoTrait uses `Webiny` as a default service name
        $this->mongo()->getCollectionNames();

        // If you have specified your own service name, pass it to mongo method
        $this->mongo('MyMongo')->getCollectionNames();
    }
}

ResultClass

ResultClass is used to wrap all Mongo command results. This allows us to have a compatibility layer in case something changes in Mongo response structures in the future and also allows any developer to extend this class and add custom methods to handle mongo response flags.

Indexes

Currently Mongo component supports 3 types of indexes:

  • SingleIndex
  • CompoundIndex
  • TextIndex

To create an index on your collection:

// Create a unique single index object
$index = new SingleIndex('Name', 'name', false, true);

// Use mongo trait to create index on your collection
$this->mongo()->createIndex('MyCollection', $index);

Resources

To run unit tests, you need to use the following command:

$ cd path/to/Webiny/Component/Mongo/
$ composer.phar install
$ phpunit

Make sure you set your MongoDb driver settings in Tests\ExampleConfig.yaml.

统计信息

  • 总下载量: 155
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 9
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-08-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固