App42 Cloud API

PHP cloud SDK

NoSQL Storage

Storage service on cloud provides the way to store the JSON document in NoSQL database running on cloud. One can store the JSON document, update it , search it and can apply the map-reduce search on stored documents. Example : If one will store JSON doc {"date":"5Feb"} it will be stored with unique Object Id and stored JSON object will loook like { "date" : "5Feb" , "_id" : { "$oid" : "4f423dcce1603b3f0bd560cf"}}. This oid can further be used to access/search the document.

In order to use the various functions available under a particular API, a developer will have to create an instance of ServiceAPI by passing the apiKey and the secretKey which has been received while creating an app.

$api = new ServiceAPI("<API_KEY>","<SECRET_KEY>"); 

After initialization, developer needs to call the buildXXXService method on ServiceAPI instance to get the instance of the particular API that you wish to build. For example, To build an instance of StorageService, buildStorageService() method needs to be called.

	$storageService= $api->buildStorageService();;

Once the API instance has been retrieved, You are ready to use the functions available for that particular API.

The methods available under a particular API will return the user domain object (like Storage in this case) as a response which will have the accessor / mutator to access the available properties for that object. You can get the response in the form of JSON as well. We have provided the JSON response with every function detail which can be retrieved by calling the toString() on the returned object.

$dbName = "test";
$collectionName = "foo";
$json = "{\"employeeName \":\"Nick\"}";

$storage = $storageService->insertJSONDocument($dbName,$collectionName,$json); /* returns the Storage object. */ 
print_r("dbName is " . $storage->getDbName());
print_r("Collection Name is " . $storage->getCollectionName());
$jsonDocList = $storage->getJsonDocList();               
for($jsonDocList as $jsonDoc)
{
print_r("docId is" . $jsonDoc->getDocId());
print_r("JsonDoc is" . $jsonDoc->getJsonDoc());
}
$jsonResponse = $storage->toString(); /* returns the response in JSON format. */ 

The functions available under Storage API can throw some exceptions in abnormal conditions. Example of the same has been given below.

E.g. If App developer is requesting for the document that does not exist, the function will throw the Exception with message as "Not Found" and the appErrorCode as "2600" and the details as "Document by the Id '<docId>' does not exist".

$dbName = "test";
$collectionName = "foo";
$docId = "4faa3f1ac68df147a51f8bd7";
							
try{
	$storage = $storageService->findDocumentById($dbName, $collectionName, $docId);
   } 
catch(App42Exception $ex) 
{
	$appErrorCode = $ex->getAppErrorCode();
	$httpErrorCode = $ex->getHttpErrorCode();
	if(appErrorCode == 2600)
{
    // Handle here for Not Found (Document by the Id '<docId>' does not exist.)
}
    else if(appErrorCode  == 2606){
    // Handle here for Bad Request (Document Id '<docId>' is not valid.)
}
    else if(appErrorCode == 1401)
{
    // handle here for Client is not authorized
}
    else if(appErrorCode == 1500){
    // handle here for Internal Server Error
}
	$jsonText = $ex->getMessage(); /* returns the Exception text in JSON format. (as shown below)*/	
}
                            
	{
	   "app42Fault": {
		   "httpErrorCode": 404,
		   "appErrorCode": 2600,
		   "message": "Not Found",
		   "details": "Document by the Id '4faa3f1ac68df147a51f8bd7' does not Exist"
	   }
	}							

Below are the HTTP Error Codes and their description, the function under the Storage API can throw.

/*
1400 - BAD REQUEST - The Request parameters are invalid
1401 - UNAUTHORIZED - Client is not authorized
1500 - INTERNAL SERVER ERROR - Internal Server Error. Please try again	
*/						

Below are the Application Error Codes and their description, the function under the Storage API can throw.

/*
2600 - NOT FOUND - Document by the Id '<docId>' does not exist. 
2601 - NOT FOUND - Document by key '<key>' and value '<value>' does not exist.
2602 - NOT FOUND - No document in the collection '<collectionName>' exists.
2603 - BAD REQUEST - The request parameters are invalid. Make Sure DB and collection name exists and functions are syntactically correct. 
2604 - NOT FOUND - No storage exist with the name '<storageName>'.
2605 - BAD REQUEST - Passed JSON string '<newjsonDoc>'is not valid.
2606 - BAD REQUEST - Document Id '<docId>' is not valid.
2607 - NOT FOUND - The number of documents in the collection '<collectionName>' are less than the specified offset : <offset>
*/				

Various functions available under Storage API has been explained below.

function insertJSONDocument($dbName, $collectionName, $json)

Save the JSON document in given database name and collection name.

Parameters:

dbName - Unique handler for storage name
collectionName - Name of collection under which JSON doc has to be saved
json - Target JSON document to be saved

Returns:

Storage object

Response: Storage Object

Exception:

This method throws following exception.
/*
2605 - BAD REQUEST - Passed JSON string '<newjsonDoc>' is not valid.	
*/			  
        
For more details click Exception
$dbName = "test";
$collectionName = "foo";
$json = "{\"employeeName \":\"Nick\"}";

$storage = $storageService->insertJSONDocument($dbName, $collectionName, $json); /* returns the Storage object. */ 
print_r("dbName is " . $storage->getDbName());
print_r("Collection Name is " . $storage->getCollectionName());
$jsonDocList = $storage->getJsonDocList();  
foreach( $jsonDocList as $jsonDoc )
{
print_r("docId is" . $jsonDoc->getDocId());
print_r("jsonDocs is" . $jsonDoc->getJsonDoc());
}

$jsonResponse = $storage->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": {
                    "employeeName": "Nick",
                    "_id": {
                        "$oid": "4faa3f1ac68df147a51f8bd7"
                    }
                }
            }
        }
    }
}
function findAllDocuments($dbName, $collectionName)

Find all documents stored in given database and collection.

Parameters:

dbName - Unique handler for storage name
collectionName - Name of collection under which JSON doc needs to be searched

Returns:

Storage object

Response: Storage Object

Exception:

This method throws following exception.
/*
2602 - NOT FOUND - No document in the collection '<collectionName>' exists. 	
*/			  
        
For more details click Exception
$dbName = "test";
$collectionName = "foo";
						
$storage = $storageService->findAllDocuments($dbName, $collectionName); /* returns the Storage object. */ 
print_r("dbName is " . $storage->getDbName());
print_r("Collection Name is " . $storage->getCollectionName());
$jsonDocList = $storage->getJsonDocList();  
foreach( $jsonDocList as $jsonDoc )
{
print_r("docId is" . $jsonDoc->getDocId());
print_r("jsonDocs is" . $jsonDoc->getJsonDoc());
}

$jsonResponse = $storage->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": [
                    {
                        "_id": {
                            "$oid": "50470db9c68d8e2fae75653e"
                        },
                        "employeeName": "Nick"
                    },
                    {
                        "_id": {
                            "$oid": "50470dccc68d8e2fae75653f"
                        },
                        "employeeName": "Nick"
                    },
                    {
                        "_id": {
                            "$oid": "50470e8fc68d8e2fae756540"
                        },
                        "employeeName": "Gill"
                    }
                ]
            }
        }
    }
}
function findAllDocumentsCount($dbName, $collectionName)

Find all documents stored in given database and collection.

Parameters:

dbName - Unique handler for storage name
collectionName - Name of collection under which JSON doc needs to be searched

Returns:

App42Response object

Response: App42Response Object

For more details click Exception
$dbName = "test";
$collectionName = "foo";

$response = $storage->findAllDocumentsCount($dbName,$collectionName); /* returns the App42Response objects. */
$success = $response->isResponseSuccess();
$jsonResponse = $response->toString(); /* returns the response in JSON format. (as shown below)*/ 
{
    "app42": {
        "response": {
            "success": true,
            "totalRecords": 96
        }
    }
}
def findAllDocuments($dbName,$collectionName,$max,$offset)

Find all documents stored in given database and collection.

Parameters:

dbName - Unique handler for storage name
collectionName - Name of collection under which JSON doc needs to be searched
max - Maximum number of records to be fetched
offset - From where the records are to be fetched

Returns:

Storage object

Response: App42Response Object

Exception:

This method throws following exception.
/*
2607 - Not Found - The number of documents in the collection '<collectionName>' are less than the specified offset : '<offset>'.
*/		       
For more details click Exception
$dbName = "test";
$collectionName = "foo";
$max = 1;
$offset = 0;						

$storage = $storageService->findAllDocuments($dbName,$collectionName,$max,$offset); /* returns the Storage object. */ 
print_r("dbName is " . $storage->getDbName());
print_r("Collection Name is " . $storage->getCollectionName());
$jsonDocList = $storage->getJsonDocList();               
for($jsonDocList as $jsonDoc)
{
print_r("docId is " . $jsonDoc->getDocId());
print_r("JsonDoc is " . $jsonDoc->getJsonDoc());
}
$jsonResponse = $storage->toString(); /* returns the response in JSON format. (as shown below)*/     
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": [
                    {
                        "_id": {
                            "$oid": "4faa3f1ac68df147a51f8bd7"
                        },
                        "employeeName": "Nick"
                    }
                ]
            }
        }
    }
}
function findDocumentById($dbName, $collectionName, $docId)

Find target document by given unique object id.

Parameters:

dbName - Unique handler for storage name
collectionName - Name of collection under which JSON doc needs to be searched
docId - Unique Object Id handler

Returns:

Storage object

Response: Storage Object

Exception:

This method throws following exception.
/*
2600 - NOT FOUND - Document by the Id '<docId>' does not exist.
2606 - BAD REQUEST - Document Id '<docId>' is not valid		
*/			  
        
For more details click Exception
$dbName = "test";
$collectionName = "foo";
$docId = "4faa3f1ac68df147a51f8bd7";
						
$storage = $storageService->findDocumentById($dbName, $collectionName, $docId); /* returns the Storage object. */ 
print_r("dbName is " . $storage->getDbName());
print_r("Collection Name is " . $storage->getCollectionName());
$jsonDocList = $storage->getJsonDocList();  
foreach( $jsonDocList as $jsonDoc )
{
print_r("docId is" . $jsonDoc->getDocId());
print_r("jsonDocs is" . $jsonDoc->getJsonDoc());
}
$jsonResponse = $storage->toString(); /* returns the response in JSON format. (as shown below)*/ 
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": {
                    "_id": {
                        "$oid": "50471017c68d8e2fae756545"
                    },
                    "employeeName": "Nick"
                }
            }
        }
    }
}
function findDocumentByKeyValue($dbName, $collectionName, $key, $value)

Find target document using key value search parameter. This key value pair will be searched in the JSON doc stored on the cloud and matching Doc will be returned as a result of this method.

Parameters:

dbName - Unique handler for storage name
collectionName - Name of collection under which JSON doc needs to be searched
key - Key to be searched for target JSON doc
value - Value to be searched for target JSON doc

Returns:

Storage object

Response: Storage Object

Exception:

This method throws following exception.
/*
2601 - NOT FOUND - Document by key '<key>' and value '<value>' does not exist.
*/			  
        
For more details click Exception
$dbName = "test";
$collectionName = "foo";
$key = "employeeName";
$value = "Nick";
						
$storage = $storageService->findDocumentByKeyValue($dbName, $collectionName, $key, $value); /*the Storage object. */ 
print_r("dbName is " . $storage->getDbName());
print_r("Collection Name is " . $storage->getCollectionName());
$jsonDocList = $storage->getJsonDocList();  
foreach( $jsonDocList as $jsonDoc )
{
print_r("docId is" . $jsonDoc->getDocId());
print_r("jsonDocs is" . $jsonDoc->getJsonDoc());
}
$jsonResponse = $storage->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": {
                    "employeeName": "Nick",
                    "_id": {
                        "$oid": "50470f5fc68d8e2fae756544"
                    }
                }
            }
        }
    }
}
function findDocumentsByQuery($dbName,$collectionName,$query)

Find target document using Custom Query.

Parameters:

dbName - Unique handler for storage name.
collectionName - Name of collection under which JSON doc needs to be searched
query - Query Object containing custom query for searching docs

Returns:

Storage object

Response: Storage Object

Exception:

The method throws the following exception with the error code.
/*
2605 - BAD REQUEST - Invalid Storage Query.
2608 - NOT FOUND - No document in the collection '<collectionName>' exists for given query.
*/		        
For more details click Exception
$dbName = "test";
$collectionName = "foo";
$query = new QueryBuilder();
$q1 = $query->build("name", "shephertz", Operator::LIKE);

$storage = $storageService->findDocumentsByQuery($dbName,$collectionName,$q1); /*the Storage object. */ 
print_r("dbName is " . $storage->getDbName());
print_r("Collection Name is " . $storage->getCollectionName());
$jsonDocList = storage->getJsonDocList();      
for($jsonDocList as $jsonDoc)
{
    print_r("docId is " . $jsonDoc->getDocId());
    print_r("JsonDoc is " . $jsonDoc->getJsonDoc());
}
$jsonResponse = $storage->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": [
                    {
                        "_id": {
                            "$oid": "507bq526c68d198fe882d0d4"
                        },
                        "name": "shephertz",
                    }
                ]
            }
        }
    }
}
function findDocumentsByQuery($dbName,$collectionName,$query)

Find target document using Custom Query.

Parameters:

dbName - Unique handler for storage name.
collectionName - Name of collection under which JSON doc needs to be searched
query - Query Object containing custom query for searching docs

Returns:

Storage object

Response: Storage Object

Exception:

The method throws the following exception with the error code.
/*
2605 - BAD REQUEST - Invalid Storage Query.
2608 - NOT FOUND - No document in the collection '<collectionName>' exists for given query.
*/		        
For more details click Exception
$dbName = "test";
$collectionName = "foo";
$query = new QueryBuilder();
Query q1 = $query->build("NickScore", 300, Operator::LESS_THAN_EQUALTO);
Query q2 = $query->build("name", "shephertz", Operator::LIKE);	
Query q3 = $query->compoundOperator($q1, Operator::ANDop, $q2);	

$storage = $storageService->findDocumentsByQuery($dbName,$collectionName,$q3); /*the Storage object. */ 
print_r("dbName is " . $storage->getDbName());
print_r("Collection Name is " . $storage->getCollectionName());
$jsonDocList = storage->getJsonDocList();      
for($jsonDocList as $jsonDoc)
{
    print_r("docId is " . $jsonDoc->getDocId());
    print_r("JsonDoc is " . $jsonDoc->getJsonDoc());
}
$jsonResponse = $storage->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": [
                    {
                        "_id": {
                            "$oid": "507bq526c68d198fe882d0d4"
                        },
                        "name": "shephertz",
                        "NickScore": 300
                    }
                ]
            }
        }
    }
}
function findDocumentsByQuery($dbName,$collectionName,$query)

Find target document using Custom Query.

Parameters:

dbName - Unique handler for storage name.
collectionName - Name of collection under which JSON doc needs to be searched
query - Query Object containing custom query for searching docs

Returns:

Storage object

Response: Storage Object

Exception:

The method throws the following exception with the error code.
/*
2605 - BAD REQUEST - Invalid Storage Query.
2608 - NOT FOUND - No document in the collection '<collectionName>' exists for given query.
*/		        
For more details click Exception
$dbName = "test";
$collectionName = "foo";
$query = new QueryBuilder();
$q1 = $query->build("NickScore", 300, Operator::LESS_THAN_EQUALTO);
$q2 = $query->build("name", "", Operator::LIKE);
$q3 = $query->compoundOperator($q1, Operator::ANDop, $q2);	

						
$storage = $storageService->findDocumentsByQuery($dbName,$collectionName,$q3); /*the Storage object. */ 
print_r("dbName is " . $storage->getDbName());
print_r("Collection Name is " . $storage->getCollectionName());
$jsonDocList = storage->getJsonDocList();      
for($jsonDocList as $jsonDoc)
{
    print_r("docId is " . $jsonDoc->getDocId());
    print_r("JsonDoc is " . $jsonDoc->getJsonDoc());
}
$jsonResponse = $storage->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": [
                    {
                        "_id": {
                            "$oid": "507bq526c68d198fe882d0d4"
                        },
                        "name": "shephertz",
                        "NickScore": 300
                    }
                ]
            }
        }
    }
}
function findDocumentsByQueryWithPaging($dbName, $collectionName, $query,$max,$offset)

Find target document using Custom Query with paging.

Parameters:

dbName - Unique handler for storage name
collectionName - Name of collection under which JSON doc needs to be searched
query - Query Object containing custom query for searching docs
max - max result parameter
offset - offset result parameter

Returns:

Storage object

Response: Storage Object

Exception:

The method throws the following exception with the error code.
/*
2605 - BAD REQUEST - Invalid Storage Query.
2608 - NOT FOUND - No document in the collection '<collectionName>' exists for given query.
*/		        
For more details click Exception
$dbName = "test";
$collectionName = "foo";
$query = new QueryBuilder();
$q1 = $query.build("NickScore", 500, Operator::LESS_THAN_EQUALTO);
$q2 = $query.build("name", "Ni", Operator::LIKE);	
$q3 = $query.compoundOperator($q1, Operator::ANDop, $q2);			
$max = 1;
$offset = 0;

$storage = $storageService->findDocumentsByQueryWithPaging($dbName,$collectionName,$q3,$max,$offset); /* returns the Storage object. */ 
print_r("dbName is " . $storage->getDbName());
print_r("Collection Name is " + $storage->getCollectionName());
$jsonDocList = $storage->getJsonDocList();               
for($jsonDocList as $jsonDoc)
{
    print_r("docId is " . $jsonDoc->getDocId());
    print_r("JsonDoc is " . $jsonDoc->getJsonDoc());
}
$jsonResponse = $storage->toString(); /* returns the response in JSON format. (as shown below)*/       
                            
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": [
                    {
                        "_id": {
                            "$oid": "507bc528e68d198fe882d0d4"
                        },
                        "name": "Nick",
                        "NickScore": 400
                    }
                ]
            }
        }
    }
}
function findDocsWithQueryPagingOrderBy($dbName,$collectionName,$query,$max,$offset,$orderByKey,$type)

Find target document using Custom Query with paging and orderby.

Parameters:

dbName - Unique handler for storage name
collectionName - Name of collection under which JSON doc needs to be searched
query - Query Object containing custom query for searching docs
max - max result parameter
offset - offset result parameter
orderByKey - Key to be searched for target JSON doc
type - Sorts the document by its type either ASCENDING or DESCENDING

Returns:

Storage object

Response: Storage Object

Exception:

This method throws following exception.
/*
2605 - BAD REQUEST - Invalid Storage Query.
2608 - NOT FOUND - No document in the collection '<collectionName>' exists for given query.
*/				  
        
For more details click Exception
$dbName = "test";
$collectionName = "foo";  
$query = new QueryBuilder();
$q1 = $query->build("name", "Nick", Operator::EQUALS);	
$q2 = $query->build("company", "shep", Operator::LIKE);	
$q3 = $query->compoundOperator($q1, Operator::ANDop, $q2);		
$max = 1;
$offset = 0;

$storage = $storageService->findDocsWithQueryPagingOrderBy($dbName,$collectionName,$q3,$max,$offset,"_id",OrderByType::ASCENDING); /* returns the Storage object. */ 
print_r("dbName is " . $storage->getDbName());
print_r("Collection Name is " . $storage->getCollectionName());
$jsonDocList = $storage->getJsonDocList();               
for($jsonDocList as $jsonDoc)
{
    print_r("docId is " . $jsonDoc->getDocId());
    print_r("JsonDoc is " . $jsonDoc->getJsonDoc());
}
$jsonResponse = $storage->toString(); /* returns the response in JSON format. (as shown below)*/      
                            
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": [
                    {
                        "_id": {
                            "$oid": "507bj236c68d2b42bc4f23db"
                        },
                        "name": "Nick",
                        "company": "shephertz"
                    }
                ]
            }
        }
    }
} 
function updateDocumentByDocId($dbName, $collectionName, $docId, $newJsonDoc)

Update target document using the document id.

Parameters:

dbName - Unique handler for storage name
collectionName - Name of collection under which JSON doc needs to be searched.
docId - Id of the document to be updated.
newJsonDoc - New Json document to be added.

Returns:

Storage object

Response: Storage Object

Exception:

The method throws the following exception with the error code.
/*
2605 - BAD REQUEST - Passed JSON string '<newjsonDoc>' is not valid.
*/		        
For more details click Exception
$dbName = "test";
$collectionName = "foo";
$docId = "4faa4707c68df147a51f8be1";
$newJsonDoc = "{\"employeeName \":\"Gill\"}";		

$storage = $storageService->updateDocumentByDocId($dbName, $collectionName, $docId, $newJsonDoc); /*the Storage object. */ 
print_r("dbName is " . $storage->getDbName());
print_r("Collection Name is " . $storage->getCollectionName());
$jsonDocList = $storage->getJsonDocList();  
foreach( $jsonDocList as $jsonDoc )
{
print_r("jsonDocs is" . $jsonDoc->getJsonDoc());
}
$jsonResponse = $storage->toString(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": {
                    "employeeName": "Gill"
                }
            }
        }
    }
}
function updateDocumentByKeyValue($dbName, $collectionName, $key, $value, $newJsonDoc)

Update target document using key value search parameter. This key value pair will be searched in the JSON doc stored in the cloud and matching Doc will be updated with new value passed.

Parameters:

dbName - Unique handler for storage name.
collectionName - Name of collection under which JSON doc needs to be searched
key - Key to be searched for target JSON doc
value - Value to be searched for target JSON doc.
newJsonDoc - New Json document to be added.

Returns:

Storage object

Response: Storage Object

Exception:

This method throws following exception.
/*
2601 - NOT FOUND - Document by key '<key>' and value '<value>' does not exist. 
2605 - BAD REQUEST - Passed JSON string '<newjsonDoc>' is not valid.
*/			  
        
For more details click Exception
$dbName = "test";
$collectionName = "foo";
$key = "employeeName";
$value = "Nick";
$newJsonDoc = "{\"employeeName \":\"Gill\"}";		
						
$storage = $storageService->updateDocumentByKeyValue($dbName, $collectionName, $key, $value, $newJsonDoc); /*the Storage object. */ 
print_r("dbName is " . $storage->getDbName());
print_r("Collection Name is " . $storage->getCollectionName());
$jsonDocList = $storage->getJsonDocList();  
foreach( $jsonDocList as $jsonDoc )
{
print_r("docId is" . $jsonDoc->getDocId());
print_r("jsonDocs is" . $jsonDoc->getJsonDoc());
}
$jsonResponse = $storage->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": [
                    {
                        "_id": {
                            "$oid": "4fb0dc0bc68d13dfac87d37a"
                        },
                        "employeeName": "Gill"
                    }
                ]
            }
        }
    }
}
function deleteDocumentById($dbName, $collectionName, $docId)

Delete target document using Object Id from given db and collection. The Object Id will be searched in the JSON doc stored on the cloud and matching Doc will be deleted.

Parameters:

dbName - Unique handler for storage name
collectionName - Name of collection under which JSON doc needs to be searched
docId - Unique Object Id handler

Returns:

App42Response object if deleted successfully

Response: App42Response Object

Exception:

This method throws following exception.
/*
2600 - NOT FOUND - Document by the Id '<docId>' does not exist. 
*/			  
        
For more details click Exception
$dbName = "test";
$collectionName = "foo";
$docId = "4faa4b6cc68df147a51f8be3";
						
$response = $storageService->deleteDocumentById($dbName, $collectionName, $docId); /* returns the App42Response object. */
$success = $response->isResponseSuccess();
$jsonResponse = $response->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": {
                    "_id": {
                        "$oid": "4faa3f1ac68df147a51f8bd7"
                    },
                    "employeeName": "Nick"
                }
            }
        }
    }
}
function mapReduce($dbName, $collectionName, $mapFunction, $reduceFunction)

Map reduce function to search the target document. Please see detail information on map-reduce http://en.wikipedia.org/wiki/MapReduce .

Parameters:

dbName - Unique handler for storage name.
collectionName - Name of collection under which JSON doc needs to be searched.
mapFunction - Map function to be used to search the document
reduceFunction - Reduce function to be used to search the document

Returns:

The target JSON document.

Response: Storage Object

Exception:

This method throws following exception.
/*
2603 - BAD REQUEST - The request parameters are invalid. Make Sure DB and collection name exists and functions are syntactically correct. 	
*/			  
        
For more details click Exception
$dbName = "test";
$collectionName = "foo";
$mapFunction = "function map(){ emit(this.user,1);}";
$reduceFunction = "function reduce(key, val){var sum = 0; for(var n=0;n< val.length;n++){ sum = sum + val[n]; } return sum;}";		 

$response = $storageService-> mapReduce($dbName, $collectionName, $mapFunction, $reduceFunction); /* returns the Storage object. */                             
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": [
                    {
                        "_id": null,
                        "value": 2
                    }
                ]
            }
        }
    }
}
function insertJsonDocUsingMap($dbName, $collectionName,$map)

Save the JSON document in given database name and collection name. It accepts the HashMap containing key-value and convert it into JSON. Converted JSON doc further saved on the cloud using given db name and collection name.

Parameters:

dbName - Unique handler for storage name.
collectionName - Name of collection under which JSON doc has to be saved
map - HashMap containing key-value pairs

Returns:

Storage object

Response: Storage Object

For more details click Exception
$dbName = "test";
$collectionName = "foo";
$HashMap = array("name" => "Nick", "age" => "28");
						
$storage = $storageService->insertJsonDocUsingMap($dbName, $collectionName,$HashMap); /*the Storage object. */ 
print_r("dbName is " . $storage->getDbName());
print_r("Collection Name is " . $storage->getCollectionName());
$jsonResponse = $storage->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": {
                    "name": "nick",
                    "age": "28",
                    "_id": {
                        "$oid": "50471983c68d8e2fae756551"
                    }
                }
            }
        }
    }
}