abishekrsrikaanth/mongohq-api

Laravel 4 Integration for MongoHQ API


Keywords
email, laravel, mandrill, laravel-4
License
BSD-3-Clause

Documentation

Laravel 4 Integration for MongoHQ API

Bitdeli Badge endorse

Installation

Add abishekrsrikaanth/mongohq-api as a requirement to composer.json:

{
    ...
    "require": {
        ...
        "abishekrsrikaanth/mongohq-api": "dev-master"
        ...
    },
}

Update composer:

$ php composer.phar update

Add the provider to your app/config/app.php:

'providers' => array(
    ...
    'Abishekrsrikaanth\MongohqApi\MongohqApiServiceProvider',
),

and the Facade info on app/config/app.php

'aliases'   => array(
    ...
    'MongoHQ'     => 'Abishekrsrikaanth\MongohqApi\Facades\MongohqApi',
),

Publish the Configuration and setup the API Key

php artisan config:publish abishekrsrikaanth/mongohq-api

Usage

Initializing the database Object

If the MongoHQ API Key is configured on the config file published

$db = MongoHQ::Database(); 

To pass the MongoHQ API Key dynamically

$db = MongoHQ::Database('API_KEY_GOES_HERE')

Initializing the Collections Object

If the MongoHQ API Key is configured on the config file published

$coll = MongoHQ::Collections(); 

To pass the MongoHQ API Key dynamically

$coll = MongoHQ::Collections('API_KEY_GOES_HERE')

Initializing the Indexes Object

If the MongoHQ API Key is configured on the config file published

$idx = MongoHQ::Indexes(); 

Initializing the Users Object

If the MongoHQ API Key is configured on the config file published

$idx = MongoHQ::Users(); 

To pass the MongoHQ API Key dynamically

$idx = MongoHQ::Indexes('API_KEY_GOES_HERE')

The API Key can be passed to all the initializations mentioned above


Database

Getting the list of databases

$db = MongoHQ::Database(); //Initializes the Database Class
$db->get();

Create Database

$db = MongoHQ::Database();
$db->create('DB_NAME','PLAN_TO_USE');

Get DB Info

$db = MongoHQ::Database();
$db->info('DB_NAME_TO_GET_THE_INFO');

Drop a Database

$db = MongoHQ::Database();
$db->drop('DB_NAME_TO_GET_THE_INFO');

Collections

Getting the list of collections

$coll = MongoHQ::Collections(); //Initializes the Database Class
$coll->get('DB_NAME_TO_GET_THE_LIST_COLLECTIONS');

Create a Collection

$coll = MongoHQ::Collections();
$coll->create('DB_NAME_TO_CREATE_THE_COLLECTION_ON','COLLECTION_NAME');

Getting the Collection Stats

$coll = MongoHQ::Collections();
$coll->stats('DB_NAME','COLLECTION_NAME_TO_GET_STATS');

Rename Collection

$coll = MongoHQ::Collections();
$coll->rename('DB_NAME','OLD_COLLECTION_NAME','NEW_COLLECTION_NAME');

Drop a Collection from a Database

$coll = MongoHQ::Collections();
$coll->drop('DB_NAME','COLLECTION_NAME_TO_DROP');

Indexes

Getting the list of indexes on a Collection

$idx = MongoHQ::Indexes(); //Initializes the Database Class
$idx->get('DB_NAME','COLLECTION_NAME');

Create an Index on a Collection

$idx = MongoHQ::Indexes();
$idx->create('DB_NAME','COLLECTION_NAME',
    array('name'=>'1'),  //IDX_SPEC - The index spec to be created. (i.e. {name:1})</dd>
    array(
        'background' => true, //Indicate that the index should be built in the background. (defaults to true)
        'unique'     => false, //If true, this index will enforce a uniqueness constraint. (defaults to false)
        'drop_dups'  => false, //If creating a unique index on a collection with pre-existing records, 
                             //this option will keep the first document the database 
                             //indexes and drop all subsequent with duplicate values. (defaults to false)
        'min'        => null, //Specify the minimum longitude and latitude for a geo index. (defaults to null)
        'max'        => null //Specify the maximum longitude and latitude for a geo index. (defaults to null)
        )
    );

Drop an Index on a Collection

$idx = MongoHQ::Indexes();
$idx->drop('DB_NAME','COLLECTION_NAME','IDX_NAME');

Drop all Indexes on the Collection

$idx = MongoHQ::Indexes();
$idx->dropAll('DB_NAME','COLLECTION_NAME');

Users

Creating a User on a DB on MongoHQ

$userObj = MongoHQ::Users(); //Initializes the Database Class
$userObj->create('DB_NAME','USER_NAME','PASSWORD');

The create function will internally manage the hashing of the password as required by MongoDB.