abishekrsrikaanth / mongohq-api
Laravel 4 Integration for MongoHQ API
Requires
- php: >=5.3.0
- guzzle/guzzle: 3.7.*@dev
- illuminate/support: 4.0.x
This package is auto-updated.
Last update: 2024-12-14 06:35:08 UTC
README
##Laravel 4 Integration for MongoHQ API
###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
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
####Getting the list of databases
$db = MongoHQ::Database(); //Initializes the Database Class
$db->get();
$db = MongoHQ::Database();
$db->create('DB_NAME','PLAN_TO_USE');
$db = MongoHQ::Database();
$db->info('DB_NAME_TO_GET_THE_INFO');
$db = MongoHQ::Database();
$db->drop('DB_NAME_TO_GET_THE_INFO');
####Getting the list of collections
$coll = MongoHQ::Collections(); //Initializes the Database Class
$coll->get('DB_NAME_TO_GET_THE_LIST_COLLECTIONS');
$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');
$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');
####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');
####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.