{"id":13704645,"url":"https://github.com/thephpleague/monga","last_synced_at":"2025-06-18T08:08:37.302Z","repository":{"id":57013283,"uuid":"9375502","full_name":"thephpleague/monga","owner":"thephpleague","description":"Simple and swift MongoDB abstraction.","archived":false,"fork":false,"pushed_at":"2017-11-11T06:37:31.000Z","size":242,"stargazers_count":332,"open_issues_count":4,"forks_count":30,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-05-29T21:52:34.265Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thephpleague.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-11T16:56:38.000Z","updated_at":"2025-02-11T21:30:33.000Z","dependencies_parsed_at":"2022-08-21T14:50:30.027Z","dependency_job_id":null,"html_url":"https://github.com/thephpleague/monga","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/thephpleague/monga","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thephpleague%2Fmonga","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thephpleague%2Fmonga/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thephpleague%2Fmonga/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thephpleague%2Fmonga/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thephpleague","download_url":"https://codeload.github.com/thephpleague/monga/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thephpleague%2Fmonga/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260515146,"owners_count":23020619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T21:01:15.088Z","updated_at":"2025-06-18T08:08:32.280Z","avatar_url":"https://github.com/thephpleague.png","language":"PHP","funding_links":[],"categories":["NoSQL","目录","NoSQL NoSQL","非关系型数据库( NoSQL )","类库"],"sub_categories":["NoSQL","缓存"],"readme":"# Monga\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE.md)\n[![Build Status][ico-travis]][link-travis]\n[![Total Downloads][ico-downloads]][link-downloads]\n\nA simple and swift MongoDB abstraction layer for PHP 5.4+\n\n## What's this all about?\n\n* An easy API to get connections, databases and collections.\n* A filter builder that doesn't make your mind go nuts.\n* All sorts of handy update functions.\n* An abstraction for sorting single results.\n* GridFS support for a Mongo filesystem.\n* Easy aggregation and distinct values.\n\n## Vision\n\nMonga was created with the acknowledgment of the MongoDB PHP package already being pretty awesome. That's why in a lot of cases Monga is just a simple wrapper around the MongoDB classes.\nIt provides some helpers and helps you set up queries using a query builder. Which you can also choose not to use! Everything will still work accordingly.\nDuring the development, a lot of planning has gone into creating a nice streamlined API that closely follows the MongoDB base classes, while complementing existing query builders for SQL-like databases.\n\n## Install\n\nVia Composer\n\n``` bash\n$ composer require league/monga\n```\n\n## Usage\n\n```php\n\nuse League\\Monga;\n\n// Get a connection\n$connection = Monga::connection($dns, $connectionOptions);\n\n// Get the database\n$database = $connection-\u003edatabase('db_name');\n\n// Drop the database\n$database-\u003edrop();\n\n// Get a collection\n$collection = $database-\u003ecollection('collection_name');\n\n// Drop the collection\n$collection-\u003edrop();\n\n// Truncate the collection\n$collection-\u003etruncate();\n\n// Insert some values into the collection\n$insertIds = $collection-\u003einsert([\n\t[\n\t\t'name' =\u003e 'John',\n\t\t'surname' =\u003e 'Doe',\n\t\t'nick' =\u003e 'The Unknown Man',\n\t\t'age' =\u003e 20,\n\t],\n\t[\n\t\t'name' =\u003e 'Frank',\n\t\t'surname' =\u003e 'de Jonge',\n\t\t'nick' =\u003e 'Unknown',\n\t\t'nik' =\u003e 'No Man',\n\t\t'age' =\u003e 23,\n\t],\n]);\n\n// Update a collection\n$collection-\u003eupdate(function ($query) {\n\t$query-\u003eincrement('age')\n\t\t-\u003eremove('nik')\n\t\t-\u003eset('nick', 'FrenkyNet');\n});\n\n// Find Frank\n$frank = $collection-\u003efindOne(function ($query) {\n\t$query-\u003ewhere('name', 'Frank')\n\t\t-\u003ewhereLike('surname', '%e Jo%');\n});\n\n// Or find him using normal array syntax\n$frank = $collection-\u003efind([\n\t'name' =\u003e 'Frank',\n\t'surname' =\u003e new MongoRegex('/e Jo/imxsu')\n]);\n\n$frank['age']++;\n\n$collection-\u003esave($frank);\n\n// Also supports nested queries\n$users = $collection-\u003efind(function ($query) {\n\t$query-\u003ewhere(function ($query) {\n\t\t$query-\u003ewhere('name', 'Josh')\n\t\t\t-\u003eorWhere('surname', 'Doe');\n\t})-\u003eorWhere(function ($query) {\n\t\t$query-\u003ewhere('name', 'Frank')\n\t\t\t-\u003ewhere('surname', 'de Jonge');\n\t});\n});\n\n// get the users as an array\n$arr = $users-\u003etoArray();\n```\n\n## Aggregation\n\nA big part of the newly released MongoDB pecl package is aggregation support. Which is super easy to do with Monga:\n\n```php\n$collection-\u003eaggregate(function ($a) {\n\t$a-\u003eproject([\n\t\t'name' =\u003e 1,\n\t\t'surname' =\u003e -1,\n\t\t'tags' =\u003e 1,\n\t])-\u003eunwind('tags');\n\n\t// But also more advanced groups/projections\n\t$a-\u003eproject(function ($p) {\n\t\t$p-\u003eselect('field')\n\t\t\t-\u003eselect('scores')\n\t\t\t-\u003eexclude('other_field');\n\t})-\u003egroup(function ($g) {\n\t\t$g-\u003eby(['$name', '$surname'])\n\t\t\t-\u003esum('scores');\n\t});\n});\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email bryan@bryan-crowe.com instead of using the issue tracker.\n\n## Credits\n\n- [Frank de Jonge][link-author]\n- [All Contributors][link-contributors]\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/league/monga.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-travis]: https://img.shields.io/travis/thephpleague/monga/master.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/league/monga.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/league/monga\n[link-travis]: https://travis-ci.org/thephpleague/monga\n[link-downloads]: https://packagist.org/packages/league/monga\n[link-author]: https://github.com/frankdejonge\n[link-contributors]: ../../contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthephpleague%2Fmonga","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthephpleague%2Fmonga","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthephpleague%2Fmonga/lists"}