• Stars
    star
    211
  • Rank 186,867 (Top 4 %)
  • Language
    PHP
  • License
    BSD 3-Clause "New...
  • Created almost 15 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple but powerful set of wrappers for using MongoDb in PHP (also a Kohana 3 module)

MongoDb PHP ODM

(for lack of a better title)

Overview

MongoDb PHP ODM is a simple object wrapper for the Mongo PHP driver classes which makes using Mongo in your PHP application more like ORM, but without the suck. It is designed for use with Kohana 3 but will also integrate easily with any PHP application with almost no additional effort.

Design Principles

  • Don’t become overly complex. There are some features that could be implemented, but if they are not it is because they would increase the complexity too much, sacrificing elegance and usability.
  • Keep Mongo schema-less. I like schema-less. Requiring schema’s in your model definitions is not schema-less. This library let’s you be schema-less.
  • Follow Mongo driver convention. In many ways, using this library will be pretty similar to using the official driver.
  • Do not add unnecessary overhead. Sure, it is not as fast as using the driver directly, but I’m quite sure you won’t notice the difference.
  • Don’t Repeat Yourself. Very little code will be repeated while using this library.
  • Reduce the number of database requests/updates. Prevent redundant requests and multiple updates to the same document.
  • Choose your favorite design pattern. This library now supports using Mongo_Collection directly as a convenience wrapper, or choose between two ActiveRecord like patterns that resemble either the Table Data Gateway pattern or the Row Data Gateway pattern

Basic Idea

The basic idea is to boil the usage of the Mongo PHP library down to three classes:

  • Mongo_Database
  • Mongo_Collection
  • Mongo_Document

Mongo_Database

This class encapsulates the functionality of the Mongo connection and the MongoDb class into one since in most cases an application will interface with only one database. Interfacing with more than one database is still possible, but they will not share a single connection. Features afforded by this class:

  • Configurations are described with names such as ‘default’. Kohana loads this configuration in the typical Kohana fashion, other frameworks can simply specify it as an argument to Mongo_Database::instance('default',array(...)) to set the default configuration.
  • Database names are never used in your code other than when supplying the configuration the first time. Easily deploy the same application on different database names.
  • When used with Kohana, all important database operations can easily have profiling enabled. Profiling output mimics Mongo shell syntax for easy copy/paste debugging in the shell.
  • Lazy database connections.

Mongo_Collection

This class accomplishes the following:

  • Allows query results to be accessed as an iterator of models rather than arrays when used in conjunction with Mongo_Document.
  • Combines the functionality of MongoCollection, MongoGridFS and MongoCursor into one base class.
  • Allows query building by aggregating query parameters, cursor options, requested fields, etc..
  • When used with Kohana, all database requests can easily be profiled.
  • Debugging can be made easier by using the __toString() method to get a string representing the full query, again mimicking the syntax of the MongoDb shell.

Mongo_Document

This class objectifies a document (or row) in the database. Extend the base class for each of your data models, typically one per collection and enjoy some very simple CRUD operations with niceties like:

  • before_* and after_* methods for you to implement for transparently added functionality such as updating timestamps, validation, etc..
  • helpers for all of the Mongo update operations which are aggregated until the next save()
  • aliased field names so you can use short field names in the database and long names in the code. Take it or leave it.
  • auto-loading of referenced documents. E.g. echo $post->user->email
  • lazy-loading of documents and referenced documents. E.g. the above is two requests, this would only be one: echo $post->user->id

See the wiki for more detail.

More Information

@copyright Copyright © 2013 Colin Mollenhour (http://colin.mollenhour.com) This project is licensed under the “New BSD” license (see LICENSE.txt).

Contributors

  • @panrafal
  • @sergeyklay
  • @Xobb
  • @sebicas
  • @kanema
  • @semalead
  • @bbedwell
  • @kohenkatz

More Repositories

1

modman

Modularize extensions using symlinks. Voted #1 Magento tool by @WebShopApps!
Shell
727
star
2

Cm_Cache_Backend_Redis

A Zend_Cache backend for Redis with full support for tags (works great with Magento)
PHP
391
star
3

Cm_RedisSession

Redis-based session handler for Magento with optimistic locking
PHP
212
star
4

magento-lite

Magento CE stripped down to a general-purpose framework.
PHP
171
star
5

Cm_Cache_Backend_File

Much improved replacement for Zend_Cache_Backend_File - works great with Magento!
PHP
146
star
6

Cm_Diehard

Advanced full page cache module for Magento supporting multiple caching methods (browser, reverse proxies, app cache) and multiple hole-punching methods (Ajax, ESI and server-side). Use with any caching reverse proxy or standalone.
PHP
131
star
7

magento-mongo

MongoDb abstraction layer and atomic job queue for Magento
PHP
124
star
8

magento-cache-benchmark

Benchmarking script for comparing performance of Magento cache backends.
PHP
79
star
9

php-redis-session-abstract

A Redis-backed PHP session handler with optimistic locking
PHP
61
star
10

Cm_OrderProducts

Add Product SKUs or Names column to the Magento Orders Grid
PHP
35
star
11

node-caching-proxy

A caching reverse proxy powered by Node.js and MongoDb.
JavaScript
18
star
12

Cm_Saas

PHP
9
star
13

magento-zend

Mirror of Zend Framework classes for use with magento-lite module
PHP
6
star
14

Cm_MongoSession

A session handler for Magento powered by MongoDb efficiently implementing optimistic locking
PHP
6
star
15

Logger

PHP
6
star
16

Cm_DiehardSample

A sample implementation of Cm_Diehard
PHP
5
star
17

Cm_MountStorage

Magento media storage driver using a mounted filesystem as a backend.
PHP
5
star
18

docker-confd-firewall

Docker container for managing firewall via etcd and environment variables.
Shell
4
star
19

haproxy-service

A Docker container for HAProxy with auto-updating config based on DNS resolution (Docker Swarm, Kontena, etc).
Shell
3
star
20

docker-nodeadmin

Dockerfile for NodeAdmin
JavaScript
1
star
21

pulumi-gcp-vault

Serverless Vault with Pulumi and Cloud Run
TypeScript
1
star