pmc/mongostorage

This package is abandoned and no longer maintained. No replacement package was suggested.

A simple wrapper to speed up working with MongoDB

This package has no released version yet, and little information is available.


README

What this is NOT!

Unusually, I am going to start by saying what MongoStorage is not...

It IS NOT an ODM or any type of automatic object mapper, nor is it intended to add an abstraction layer between your application and MongoDB. Personally, I don't like ODM's and ORM's, and prefer to keep closer control over how I use database access in my applications.

What this is

MongoStorage is a small collection of abstract classes and interfaces that provide a simple wrapper around the PHP mongodb driver, and gives you a quick start to using mongodb in your application. It provides an interface for mapping mongo documents to your models, but you still have to write the actual mapping yourself!

There are three parts, the iMongoStorable interface, the ResultSet, and the StorageHelper. Theres a bit more detail on each of these below, but to get the complete picture, read the source code and have a look at the example.

Pmc\MongoStorage\iMongoStorable

This interface defines three methods: fromMongo(), toMongo() and getId() which you will implement in your models to provide a means of converting them to and from an array that can be stored in mongodb.

Pmc\MongoStorage\ResultSet

You'll have to provide a concrete ResultSet class that extends this abstract class for each type of model you have. However, the minimum code required is a single one line "getModel()" method.

The base class implements the Iterator, and Countable interface so you can use the result set directly with foreach() and count(). It also provides basic pagination.

Pmc\MongoStorage\Helper

Another abstract class that you extend to write your database queries. Normally, instead of returning the MongoCursor result from the query, you'll return the appropriate ResultSet that you have created.

Installation

The quickest way to install is by using composer. Just add it to your composer.json file in the "require" section. Eg.

"require": {
    ...
    "pmc/mongostorage": "dev-master",
    ...
}

Get in touch

I'd love to hear from you if you find this useful, or if you have any ideas for improvements or pull requests!