Laravel 4 Integration for MongoHQ API
, (*1)
, (*2)
Installation
Add abishekrsrikaanth/mongohq-api as a requirement to composer.json:, (*3)
{
...
"require": {
...
"abishekrsrikaanth/mongohq-api": "dev-master"
...
},
}
Update composer:, (*4)
$ php composer.phar update
Add the provider to your app/config/app.php:, (*5)
'providers' => array(
...
'Abishekrsrikaanth\MongohqApi\MongohqApiServiceProvider',
),
and the Facade info on app/config/app.php, (*6)
'aliases' => array(
...
'MongoHQ' => 'Abishekrsrikaanth\MongohqApi\Facades\MongohqApi',
),
Publish the Configuration and setup the API Key, (*7)
php artisan config:publish abishekrsrikaanth/mongohq-api
, (*8)
Usage
Initializing the database Object, (*9)
If the MongoHQ API Key is configured on the config file published, (*10)
$db = MongoHQ::Database();
To pass the MongoHQ API Key dynamically, (*11)
$db = MongoHQ::Database('API_KEY_GOES_HERE')
Initializing the Collections Object, (*12)
If the MongoHQ API Key is configured on the config file published, (*13)
$coll = MongoHQ::Collections();
To pass the MongoHQ API Key dynamically, (*14)
$coll = MongoHQ::Collections('API_KEY_GOES_HERE')
Initializing the Indexes Object, (*15)
If the MongoHQ API Key is configured on the config file published, (*16)
$idx = MongoHQ::Indexes();
Initializing the Users Object, (*17)
If the MongoHQ API Key is configured on the config file published, (*18)
$idx = MongoHQ::Users();
To pass the MongoHQ API Key dynamically, (*19)
$idx = MongoHQ::Indexes('API_KEY_GOES_HERE')
The API Key can be passed to all the initializations mentioned above, (*20)
, (*21)
Database
, (*22)
Getting the list of databases
$db = MongoHQ::Database(); //Initializes the Database Class
$db->get();
, (*23)
Create Database
$db = MongoHQ::Database();
$db->create('DB_NAME','PLAN_TO_USE');
, (*24)
Get DB Info
$db = MongoHQ::Database();
$db->info('DB_NAME_TO_GET_THE_INFO');
, (*25)
Drop a Database
$db = MongoHQ::Database();
$db->drop('DB_NAME_TO_GET_THE_INFO');
, (*26)
Collections
, (*27)
Getting the list of collections
$coll = MongoHQ::Collections(); //Initializes the Database Class
$coll->get('DB_NAME_TO_GET_THE_LIST_COLLECTIONS');
, (*28)
Create a Collection
$coll = MongoHQ::Collections();
$coll->create('DB_NAME_TO_CREATE_THE_COLLECTION_ON','COLLECTION_NAME');
, (*29)
Getting the Collection Stats
$coll = MongoHQ::Collections();
$coll->stats('DB_NAME','COLLECTION_NAME_TO_GET_STATS');
, (*30)
Rename Collection
$coll = MongoHQ::Collections();
$coll->rename('DB_NAME','OLD_COLLECTION_NAME','NEW_COLLECTION_NAME');
, (*31)
Drop a Collection from a Database
$coll = MongoHQ::Collections();
$coll->drop('DB_NAME','COLLECTION_NAME_TO_DROP');
, (*32)
Indexes
, (*33)
Getting the list of indexes on a Collection
$idx = MongoHQ::Indexes(); //Initializes the Database Class
$idx->get('DB_NAME','COLLECTION_NAME');
, (*34)
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)
)
);
, (*35)
Drop an Index on a Collection
$idx = MongoHQ::Indexes();
$idx->drop('DB_NAME','COLLECTION_NAME','IDX_NAME');
, (*36)
Drop all Indexes on the Collection
$idx = MongoHQ::Indexes();
$idx->dropAll('DB_NAME','COLLECTION_NAME');
, (*37)
Users
, (*38)
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., (*39)