2017 © Pedro Peláez
 

library mongo

Mongo Abstraction Class

image

rcastera/mongo

Mongo Abstraction Class

  • Sunday, September 29, 2013
  • by rcastera
  • Repository
  • 2 Watchers
  • 1 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Monga

A simple class for working with MongoDB. Those new to Mongo, should go through the SQL to Mongo Mapping Chart, (*1)

### Setup

Add a composer.json file to your project:, (*2)

{
  "require": {
      "rcastera/mongo": "v1.0.0"
  }
}

Then provided you have composer installed, you can run the following command:, (*3)

$ composer.phar install

That will fetch the library and its dependencies inside your vendor folder. Then you can add the following to your .php files in order to use the library (if you don't already have one)., (*4)

require 'vendor/autoload.php';

Then you need to use the relevant class, and instantiate the class. For example:, (*5)

### Getting Started

require 'vendor/autoload.php';

use rcastera\Database\Mongo\Monga;

$mongo = new Monga();

### Examples

Find all documents from contacts collections.

setDatabase('test')->setCollection('contacts')->getCollection()->find()->limit(10); ?>
hasNext()): ?>


    hasNext()): ?> getNext(); ?>

No contacts found., (*6)

Find all documents and sort by name in ascending order.

setDatabase('test')->setCollection('contacts')->getCollection()->find()->sort(array('name' => 1)); ?>
hasNext()): ?>


    hasNext()): ?> getNext(); ?>

No contacts found., (*7)

Find all documents where name = 'Richard Castera'.

setDatabase('test')->setCollection('contacts')->getCollection()->find(array('name' => 'Richard Castera')); ?>
hasNext()): ?>


    hasNext()): ?> getNext(); ?>

No contacts found., (*8)

Find where name = 'Richard Castera' and update address.
 'Richard Castera'
    );
    $updates = array(
        '$set' => array(
            'address' => '2 Smith Lane'
        )
    );
    $options = array(
        'upsert' => false
    );
?>
setDatabase('test')->setCollection('contacts')->getCollection()->update($criteria, $updates, $options); ?>



Contact updated., (*9)

Contact not updated., (*10)

Insert new document.
 'Isabella Castera',
        'age' => '3',
        'address' => '3 Smith Lane'
    );
?>
setDatabase('test')->setCollection('contacts')->getCollection()->insert($document); ?>



Contact inserted., (*11)

Contact not inserted., (*12)

Delete a document.
 'Elisabeth Castera'
    );

    $options = array(
        'justOne' => TRUE
    );
?>
setDatabase('test')->setCollection('contacts')->getCollection()->delete($criteria, $options); ?>



Contact deleted., (*13)

Contact not deleted., (*14)

### Contributing

  1. Fork it.
  2. Create a branch (git checkout -b my_branch)
  3. Commit your changes (git commit -am "Added something")
  4. Push to the branch (git push origin my_branch)
  5. Create an Issue with a link to your branch
  6. Enjoy a refreshing Coke and wait

The Versions

29/09 2013

dev-master

9999999-dev http://www.richardcastera.com

Mongo Abstraction Class

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-mongo *

 

by Richard Castera

php mongo

29/09 2013

v1.0.0

1.0.0.0 http://www.richardcastera.com

Mongo Abstraction Class

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-mongo *

 

by Richard Castera

php mongo