├── .phpunit-watcher.yml ├── .styleci.yml ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json └── src └── Dsn.php /.phpunit-watcher.yml: -------------------------------------------------------------------------------- 1 | watch: 2 | directories: 3 | - src 4 | - tests 5 | fileMask: '*.php' 6 | notifications: 7 | passingTests: false 8 | failingTests: false 9 | phpunit: 10 | binaryPath: vendor/bin/phpunit 11 | timeout: 180 12 | -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: psr12 2 | risky: true 3 | 4 | version: 8.1 5 | 6 | finder: 7 | exclude: 8 | - docs 9 | - vendor 10 | 11 | enabled: 12 | - alpha_ordered_traits 13 | - array_indentation 14 | - array_push 15 | - combine_consecutive_issets 16 | - combine_consecutive_unsets 17 | - combine_nested_dirname 18 | - declare_strict_types 19 | - dir_constant 20 | - fully_qualified_strict_types 21 | - function_to_constant 22 | - hash_to_slash_comment 23 | - is_null 24 | - logical_operators 25 | - magic_constant_casing 26 | - magic_method_casing 27 | - method_separation 28 | - modernize_types_casting 29 | - native_function_casing 30 | - native_function_type_declaration_casing 31 | - no_alias_functions 32 | - no_empty_comment 33 | - no_empty_phpdoc 34 | - no_empty_statement 35 | - no_extra_block_blank_lines 36 | - no_short_bool_cast 37 | - no_superfluous_elseif 38 | - no_unneeded_control_parentheses 39 | - no_unneeded_curly_braces 40 | - no_unneeded_final_method 41 | - no_unset_cast 42 | - no_unused_imports 43 | - no_unused_lambda_imports 44 | - no_useless_else 45 | - no_useless_return 46 | - normalize_index_brace 47 | - php_unit_dedicate_assert 48 | - php_unit_dedicate_assert_internal_type 49 | - php_unit_expectation 50 | - php_unit_mock 51 | - php_unit_mock_short_will_return 52 | - php_unit_namespaced 53 | - php_unit_no_expectation_annotation 54 | - phpdoc_no_empty_return 55 | - phpdoc_no_useless_inheritdoc 56 | - phpdoc_order 57 | - phpdoc_property 58 | - phpdoc_scalar 59 | - phpdoc_singular_inheritdoc 60 | - phpdoc_trim 61 | - phpdoc_trim_consecutive_blank_line_separation 62 | - phpdoc_type_to_var 63 | - phpdoc_types 64 | - phpdoc_types_order 65 | - print_to_echo 66 | - regular_callable_call 67 | - return_assignment 68 | - self_accessor 69 | - self_static_accessor 70 | - set_type_to_cast 71 | - short_array_syntax 72 | - short_list_syntax 73 | - simplified_if_return 74 | - single_quote 75 | - standardize_not_equals 76 | - ternary_to_null_coalescing 77 | - trailing_comma_in_multiline_array 78 | - unalign_double_arrow 79 | - unalign_equals 80 | - empty_loop_body_braces 81 | - integer_literal_case 82 | - union_type_without_spaces 83 | 84 | disabled: 85 | - function_declaration 86 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Yii Framework MongoDB extension Change Log 2 | 3 | ## 1.0.0 under development 4 | 5 | - Initial release. 6 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright © 2008 by Yii Software (https://www.yiiframework.com/) 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Yii Software nor the names of its 15 | contributors may be used to endorse or promote products derived 16 | from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 28 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Yii 4 | 5 | 6 | MongoDB 7 | 8 |

Yii Database MongoDB driver

9 |
10 |

11 | 12 | [![Latest Stable Version](https://poser.pugx.org/yiisoft/db-mongodb/v/stable.png)](https://packagist.org/packages/yiisoft/db-mongodb) 13 | [![Total Downloads](https://poser.pugx.org/yiisoft/db-mongodb/downloads.png)](https://packagist.org/packages/yiisoft/db-mongodb) 14 | [![Build status](https://github.com/yiisoft/db-mongodb/workflows/build/badge.svg)](https://github.com/yiisoft/db-mongodb/actions?query=workflow%3Abuild) 15 | [![Code Coverage](https://codecov.io/gh/yiisoft/db-mongodb/branch/master/graph/badge.svg)](https://codecov.io/gh/yiisoft/db-mongodb) 16 | [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdb-mongodb%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-mongodb/master) 17 | [![static analysis](https://github.com/yiisoft/db-mongodb/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/db-mongodb/actions?query=workflow%3A%22static+analysis%22) 18 | [![type-coverage](https://shepherd.dev/github/yiisoft/db-mongodb/coverage.svg)](https://shepherd.dev/github/yiisoft/db-mongodb) 19 | [![psalm-level](https://shepherd.dev/github/yiisoft/db-mongodb/level.svg)](https://shepherd.dev/github/yiisoft/db-mongodb) 20 | 21 | This extension provides the [MongoDB](https://www.mongodb.com/) integration for the [Yii framework](https://www.yiiframework.com). 22 | 23 | ## Requirements 24 | 25 | - [MongoDB PHP Extension](https://www.php.net/manual/en/set.mongodb.php) version 1.8.0 or higher. 26 | - MongoDB server version 3.0 or higher. 27 | - PHP 8.1 or higher. 28 | 29 | ## Installation 30 | 31 | The package could be installed with [Composer](https://getcomposer.org): 32 | 33 | ```shell 34 | composer require yiisoft/db-mongodb 35 | ``` 36 | 37 | ## General usage 38 | 39 | To use this extension, simply add the following code in your application configuration: 40 | 41 | ```php 42 | return [ 43 | //.... 44 | 'components' => [ 45 | 'mongodb' => [ 46 | 'class' => Yiisoft\Db\MongoDb\Connection::class, 47 | 'dsn' => 'mongodb://@localhost:27017/mydatabase', 48 | 'options' => [ 49 | "username" => "Username", 50 | "password" => "Password" 51 | ] 52 | ], 53 | ], 54 | ]; 55 | ``` 56 | 57 | Once you have a MongoDB connection instance, you can execute a MongoDB commands and queries 58 | using `Yiisoft\Db\MongoDb\Command`: 59 | 60 | ```php 61 | // execute command: 62 | $result = Yii::$app->mongodb->createCommand(['listIndexes' => 'some_collection'])->execute(); 63 | 64 | // execute query (find): 65 | $cursor = Yii::$app->mongodb->createCommand(['projection' => ['name' => true]])->query('some_collection'); 66 | 67 | // execute batch (bulk) operations: 68 | Yii::$app->mongodb->createCommand() 69 | ->addInsert(['name' => 'new']) 70 | ->addUpdate(['name' => 'existing'], ['name' => 'updated']) 71 | ->addDelete(['name' => 'old']) 72 | ->executeBatch('customer'); 73 | ``` 74 | 75 | Using the connection instance you may access databases and collections. 76 | Most of the MongoDB commands are accessible via `\Yiisoft\Db\MongoDb\Collection` instance: 77 | 78 | ```php 79 | $collection = Yii::$app->mongodb->getCollection('customer'); 80 | $collection->insert(['name' => 'John Smith', 'status' => 1]); 81 | ``` 82 | 83 | To perform `find` queries, you should use `\Yiisoft\Db\MongoDb\Query`: 84 | 85 | ```php 86 | use Yiisoft\Db\MongoDb\Query; 87 | 88 | $query = new Query(); 89 | // compose the query 90 | $query->select(['name', 'status']) 91 | ->from('customer') 92 | ->limit(10); 93 | // execute the query 94 | $rows = $query->all(); 95 | ``` 96 | 97 | ## Documentation 98 | 99 | - Guide: [English](docs/guide/en/README.md), [Français](docs/guide/fr/README.md), [Русский](docs/guide/ru/README.md), [日本語](docs/guide/ja/README.md) 100 | - [Internals](docs/internals.md) 101 | 102 | If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that. 103 | You may also check out other [Yii Community Resources](https://www.yiiframework.com/community). 104 | 105 | ## License 106 | 107 | The Yii Database MongoDB driver is free software. It is released under the terms of the BSD License. 108 | Please see [`LICENSE`](./LICENSE.md) for more information. 109 | 110 | Maintained by [Yii Software](https://www.yiiframework.com/). 111 | 112 | ## Support the project 113 | 114 | [![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective&logoColor=7eadf1&labelColor=555555)](https://opencollective.com/yiisoft) 115 | 116 | ## Follow updates 117 | 118 | [![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/) 119 | [![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter&logoColor=1DA1F2&labelColor=555555?style=flat)](https://twitter.com/yiiframework) 120 | [![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat&logo=telegram)](https://t.me/yii3en) 121 | [![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat&logo=facebook&logoColor=ffffff)](https://www.facebook.com/groups/yiitalk) 122 | [![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat&logo=slack)](https://yiiframework.com/go/slack) 123 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yiisoft/db-mongodb", 3 | "description": "Yii Framework MongoDB extension", 4 | "keywords": [ 5 | "yii", 6 | "mongo", 7 | "mongodb", 8 | "gridfs" 9 | ], 10 | "type": "library", 11 | "license": "BSD-3-Clause", 12 | "support": { 13 | "issues": "https://github.com/yiisoft/db-mongodb/issues?state=open", 14 | "source": "https://github.com/yiisoft/db-mongodb", 15 | "forum": "https://www.yiiframework.com/forum/", 16 | "wiki": "https://www.yiiframework.com/wiki/", 17 | "irc": "ircs://irc.libera.chat:6697/yii", 18 | "chat": "https://t.me/yii3en" 19 | }, 20 | "funding": [ 21 | { 22 | "type": "opencollective", 23 | "url": "https://opencollective.com/yiisoft" 24 | }, 25 | { 26 | "type": "github", 27 | "url": "https://github.com/sponsors/yiisoft" 28 | } 29 | ], 30 | "authors": [ 31 | { 32 | "name": "Paul Klimov", 33 | "email": "klimov.paul@gmail.com" 34 | } 35 | ], 36 | "require": { 37 | "php": "^8.1", 38 | "ext-mongodb": ">=1.8.0" 39 | }, 40 | "require-dev": { 41 | "phpunit/phpunit": "^9.5|^10.0", 42 | "roave/infection-static-analysis-plugin": "^1.6", 43 | "spatie/phpunit-watcher": "^1.23", 44 | "vimeo/psalm": "^5.20", 45 | "yiisoft/arrays": "^2.0|^3.0", 46 | "yiisoft/cache": "^1.0", 47 | "yiisoft/di": "dev-master", 48 | "yiisoft/factory": "^1.0", 49 | "yiisoft/log": "^1.0", 50 | "yiisoft/strings": "^2.0", 51 | "yiisoft/var-dumper": "^1.0" 52 | }, 53 | "autoload": { 54 | "psr-4": { 55 | "Yiisoft\\Db\\MongoDb\\": "src" 56 | } 57 | }, 58 | "autoload-dev": { 59 | "psr-4": { 60 | "Yiisoft\\Db\\MongoDb\\Tests\\": "tests" 61 | } 62 | }, 63 | "extra": { 64 | "branch-alias": { 65 | "dev-master": "1.0.x-dev" 66 | } 67 | }, 68 | "config": { 69 | "sort-packages": true, 70 | "allow-plugins": { 71 | "infection/extension-installer": true 72 | } 73 | }, 74 | "minimum-stability": "dev", 75 | "prefer-stable": true, 76 | "scripts": { 77 | "test": "phpunit --testdox --no-interaction", 78 | "test-watch": "phpunit-watcher watch" 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Dsn.php: -------------------------------------------------------------------------------- 1 |