{"id":18750679,"url":"https://github.com/webiny/mongo","last_synced_at":"2025-10-06T11:04:36.194Z","repository":{"id":20226166,"uuid":"23497995","full_name":"webiny/Mongo","owner":"webiny","description":"[READ-ONLY] MongoDB PHP driver/layer. (master at Webiny/Framework)","archived":false,"fork":false,"pushed_at":"2017-11-26T21:25:01.000Z","size":49,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-12-28T22:54:15.706Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.webiny.com/","language":"PHP","has_issues":false,"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/webiny.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-30T18:26:41.000Z","updated_at":"2023-05-21T17:38:16.000Z","dependencies_parsed_at":"2022-07-13T23:10:39.540Z","dependency_job_id":null,"html_url":"https://github.com/webiny/Mongo","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FMongo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FMongo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FMongo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FMongo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webiny","download_url":"https://codeload.github.com/webiny/Mongo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239636229,"owners_count":19672307,"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-11-07T17:12:49.160Z","updated_at":"2025-10-06T11:04:31.155Z","avatar_url":"https://github.com/webiny.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Mongo Component\n=================\n\nMongo Component is used for working with MongoDB database.\n\nInstall the component\n---------------------\nThe best way to install the component is using Composer.\n\n```bash\ncomposer require webiny/mongo\n```\nFor additional versions of the package, visit the [Packagist page](https://packagist.org/packages/webiny/mongo).\n\n## Configuring Mongo service\n\nThe recommended way of using Mongo is by defining a Mongo service. Here is an example of defining a service:\n\n```yaml\nMongo:\n    Services:\n        Webiny:\n            Class: \\Webiny\\Component\\Mongo\\Mongo\n            Arguments:\n                Uri: 127.0.0.1:27017\n                UriOptions: []\n                DriverOptions: []\n                CollectionPrefix: 'MyDatabase_'\n            Calls: \n                - [selectDatabase, [MyDatabase]]\n    Driver: \\Webiny\\Component\\Mongo\\Bridge\\MongoDb\n```\n\nCollection prefix will be automatically prepended for you to all database queries.\n\nFor more information see: [mongodb/mongo-php-library](http://mongodb.github.io/mongo-php-library/)\n\nAfter 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`:\n\n```php\nclass MyClass {\n    use MongoTrait;\n\n    public function test(){\n        // MongoTrait uses `Webiny` as a default service name\n        $this-\u003emongo()-\u003egetCollectionNames();\n\n        // If you have specified your own service name, pass it to mongo method\n        $this-\u003emongo('MyMongo')-\u003egetCollectionNames();\n    }\n}\n```\n\n### ResultClass\n`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\nand also allows any developer to extend this class and add custom methods to handle mongo response flags.\n\n### Indexes\nCurrently Mongo component supports 3 types of indexes:\n- SingleIndex\n- CompoundIndex\n- TextIndex\n\nTo create an index on your collection:\n```php\n// Create a unique single index object\n$index = new SingleIndex('Name', 'name', false, true);\n\n// Use mongo trait to create index on your collection\n$this-\u003emongo()-\u003ecreateIndex('MyCollection', $index);\n```\n\nResources\n---------\n\nTo run unit tests, you need to use the following command:\n\n    $ cd path/to/Webiny/Component/Mongo/\n    $ composer.phar install\n    $ phpunit\n\nMake sure you set your MongoDb driver settings in `Tests\\ExampleConfig.yaml`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Fmongo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebiny%2Fmongo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Fmongo/lists"}