https://github.com/photon/utils-mongodb
Various useful tools for MongoDB
https://github.com/photon/utils-mongodb
Last synced: 9 months ago
JSON representation
Various useful tools for MongoDB
- Host: GitHub
- URL: https://github.com/photon/utils-mongodb
- Owner: photon
- License: lgpl-2.1
- Created: 2015-12-07T12:44:32.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-05-24T20:57:05.000Z (about 9 years ago)
- Last Synced: 2025-07-18T03:14:23.073Z (11 months ago)
- Language: PHP
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
utils-mongodb
============
[](https://travis-ci.org/photon/utils-mongodb)
Various useful tools for MongoDB
PHP Versions
------------
- 5.6, 7.0 and 7.1 are supported and tested under travis
- Use ext-mongodb and mongodb/mongodb. Do not works anymore with legacy ext-mongo
Quick start
----------
1) Add the module in your project
composer require "photon/utils-mongodb:dev-master"
or for a specific version
composer require "photon/utils-mongodb:2.0.0"
2) Define a MongoDB connection in your project configuration
'databases' => array(
'default' => array(
'engine' => '\photon\db\MongoDB',
'server' => 'mongodb://localhost:27017/',
'database' => 'utils',
'options' => array(
'connect' => true,
),
),
),
3) Enjoy !
Counters
--------
The counter class implement a atomic counter increment and retreive.
It's a thread safe auto-increment.
1) Create a class to define a counters collection
class MyCounter extends \photon\utils\mongodb\Counter
{
const database = 'default';
const collection = 'counters';
}
2) Read / Write counter
$value = MyCounter::get('foo'); // = 0
$value = MyCounter::inc('foo'); // = 1
$value = MyCounter::get('bar'); // = 0
$value = MyCounter::get('foo'); // = 1