App42 Cloud API

Windows Phone 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.

	ServiceAPI api;
	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 storageService = api.BuildStorageService();;

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

The Windows Phone API's work in an asynchronous mode that means the response will not be available immediately and all the API methods would not return any value and have return type as void. The response will be returned in callback methods which the caller will provide to the calling method.
As mentioned above that the response will be returned in callback methods, every API method is taking instance of App42Callback (as the last parameter) which will have the implementation of 2 methods: OnSuccess & OnException.(as shown below)

	public class CallBack : App42Callback
	{
		public override void OnSuccess(Object obj)
		{
			Storage storage = (Storage) obj;
			//Do whatever you want with the user object
		}
		public override void OnException(App42Exception e)
		{
			//Do whatever you want with the exception
		}
	}
                            

The callback methods will return the response in the form of Object which will have to be type cast to the object domain object (e.g. App42Response / Storage in this case) The Domain object 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.

public override void OnSuccess(Object obj)
   {
   Storage storage = (Storage) obj; 
    String dbName =  storage.getDbName();
    String getCollectionName =  storage.getCollectionName();
   String 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 App42Exception (as shown below) with message as "Not Found" and the appErrorCode as "2600" and the details as "Document by the Id '<docId>' does not exist."

		public override void OnException(App42Exception ex)
		{
			int appErrorCode = ex.GetAppErrorCode();
			int httpErrorCode = ex.GetHttpErrorCode();
			
			String 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 '4f5086d5f32921b87de0bc6c' 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.

public void InsertJSONDocument(String dbName, String collectionName, String json, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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
String dbName = "test";
String collectionName = "foo";
String json =  "{\"employeeName \":\"Nick\"}";

storageService.InsertJSONDocument(dbName,collectionName,json,requestCallback); /* returns the Storage object. */ 
OnSuccess(Object obj){
Storage storage = (Storage) obj;
Console.WriteLine("dbName is " + storage.GetDbName());
Console.WriteLine("Collection Name is " + storage.GetCollectionName());
IList<Storage.JSONDocument> JsonDocList = storage.GetJsonDocList();  
	for(int int i=0;i <JsonDocList.Count;i++)
	{   
		Console.WriteLine("docId is " + JsonDocList[i].GetDocId());
		Console.WriteLine("JsonDoc is " + JsonDocList[i].GetJsonDoc());
	}  
String 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"
                    }
                }
            }
        }
    }
}
public void FindAllDocuments(String dbName, String collectionName, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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
storageService.FindAllDocuments(dbName,collectionName,requestCallback); /* returns the Storage object. */ 
OnSuccess(Object obj){
Storage storage = (Storage) obj;
Console.WriteLine("dbName is " + storage.GetDbName());
Console.WriteLine("Collection Name is " + storage.GetCollectionName());
IList<Storage.JSONDocument> JsonDocList = storage.GetJsonDocList();  
	for(int i=0;i <JsonDocList.Count;i++)
	{   
		Console.WriteLine("docId is " + JsonDocList[i].GetDocId());
		Console.WriteLine("JsonDoc is " + JsonDocList[i].GetJsonDoc());  
	 }  
String 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"
                    }
                ]
            }
        }
    }
}
public void FindAllDocumentsCount(String dbName, String collectionName, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

Storage object

Response: App42Response Object

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

storage.FindAllDocumentsCount(dbName,collectionName,requestCallback); /* returns the App42Response objects. */
OnSuccess(Objcet obj){
App42Response response = (App42Response) obj;
Boolean success = response.IsResponseSuccess();
String jsonResponse = response.ToString(); /* returns the response in JSON format. (as shown below)*/
}
                            
{
    "app42": {
        "response": {
            "success": true,
            "totalRecords": 96
        }
    }
}
public void FindAllDocuments(String dbName, String collectionName, int max, int offset, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

Storage object

Response: Storage 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
String dbName = "test";
String collectionName = "foo";
int max = 1;
int offset = 0;						

storageService.FindAllDocuments(dbName,collectionName,max,offset,requestCallback); /* returns the Storage object. */ 
OnSuccess(Object obj){
	Storage storage = (Storage) obj;  
	Console.WriteLine("dbName is " + storage.GetDbName());
	Console.WriteLine("Collection Name is " + storage.GetCollectionName());
	IList<Storage.JSONDocument> jsonDocList =  storage.GetJsonDocList(); /* returns the upload file list. */
	for (int i = 0; i < jsonDocList.Count; i++)
	{
		Console.WriteLine("docId is " + jsonDocList[i].GetDocId());
		Console.WriteLine("JsonDoc is " + jsonDocList[i].GetJsonDoc());
	} 
String 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"
                    }
                ]
            }
        }
    }
}
public void FindDocumentById(String dbName, String collectionName, String docId, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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
String dbName = "test";
String collectionName = "foo";
String docId = "50471017c68d8e2fae756545";

storageService.FindDocumentById(dbName,collectionName,docId,requestCallback); /* returns the Storage object. */ 
OnSuccess(Object obj){
Storage storage = (Storage) obj;
Console.WriteLine("dbName is " + storage.GetDbName());
Console.WriteLine("Collection Name is " + storage.GetCollectionName());
IList<Storage.JSONDocument> JsonDocList = storage.GetJsonDocList();  
	for(int i=0;i <JsonDocList.Count;i++)
	{   
		Console.WriteLine("docId is " + JsonDocList[i].GetDocId());
		Console.WriteLine("JsonDoc is " + JsonDocList[i].GetJsonDoc());
	 }  
String 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"
                }
            }
        }
    }
}
public void FindDocumentByKeyValue(String dbName, String collectionName, String key, String value, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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
String dbName = "test";
String collectionName = "foo";
String key = "employeeName";
String value = "Nick";	

storageService.FindDocumentByKeyValue(dbName,collectionName,key,value,requestCallback); /* returns the Storage object. */ 
OnSuccess(Object obj){
Storage storage = (Storage) obj;
Console.WriteLine("dbName is " + storage.GetDbName());
Console.WriteLine("Collection Name is " + storage.GetCollectionName());
IList<Storage.JSONDocument> JsonDocList = storage.GetJsonDocList();  
	for(int i=0;i <JsonDocList.Count;i++)
	{   
		Console.WriteLine("docId is " + JsonDocList[i].GetDocId());
		Console.WriteLine("JsonDoc is " + JsonDocList[i].GetJsonDoc());
	 }  
String 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"
                    }
                }
            }
        }
    }
}
public void FindDocumentsByQuery(String dbName, String collectionName, String query, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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
String dbName = "test";
String collectionName = "foo";
Query q1 = QueryBuilder.build("name", "shephertz", Operator.LIKE);

storageService.FindDocumentsByQuery(dbName,collectionName,q1,requestCallback); /* returns the Storage object. */ 
OnSuccess(Object obj){
Storage storage = (Storage) obj;
Console.WriteLine("dbName is " + storage.GetDbName());
Console.WriteLine("Collection Name is " + storage.GetCollectionName());
IList<Storage.JSONDocument> JsonDocList = storage.GetJsonDocList();  
	for(int i=0;i <JsonDocList.Count;i++)
	{   
		Console.WriteLine("docId is " + JsonDocList[i].GetDocId());
		Console.WriteLine("JsonDoc is " + JsonDocList[i].GetJsonDoc());
	 }  
String 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",
                    }
                ]
            }
        }
    }
}
public void FindDocumentsByQuery(String dbName, String collectionName, String query, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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
String dbName = "test";
String collectionName = "foo";
Query q1 = QueryBuilder.build("NickScore", 300, Operator.LESS_THAN_EQUALTO);
Query q2 = QueryBuilder.build("name", "shephertz", Operator.LIKE);
Query q3 = QueryBuilder.CompoundOperator(q1, Operator.AND, q2);

storageService.FindDocumentsByQuery(dbName,collectionName,q3,requestCallback); /* returns the Storage object. */ 
OnSuccess(Object obj){
Storage storage = (Storage) obj;
Console.WriteLine("dbName is " + storage.GetDbName());
Console.WriteLine("Collection Name is " + storage.GetCollectionName());
IList<Storage.JSONDocument> JsonDocList = storage.GetJsonDocList();  
	for(int i=0;i <JsonDocList.Count;i++)
	{   
		Console.WriteLine("docId is " + JsonDocList[i].GetDocId());
		Console.WriteLine("JsonDoc is " + JsonDocList[i].GetJsonDoc());
	 }  
String 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
                    }
                ]
            }
        }
    }
}
public void FindDocumentsByQuery(String dbName, String collectionName, String query, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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
String dbName = "test";
String collectionName = "foo";
Query q1 = QueryBuilder.build("NickScore", 300, Operator.LESS_THAN_EQUALTO);
Query q2 = QueryBuilder.build("name", "", Operator.LIKE);	
Query q3 = QueryBuilder.compoundOperator(q1, Operator.AND, q2);

storageService.FindDocumentsByQuery(dbName,collectionName,q3,requestCallback); /* returns the Storage object. */ 
OnSuccess(Object obj){
Storage storage = (Storage) obj;
Console.WriteLine("dbName is " + storage.GetDbName());
Console.WriteLine("Collection Name is " + storage.GetCollectionName());
IList<Storage.JSONDocument> JsonDocList = storage.GetJsonDocList();  
	for(int i=0;i <JsonDocList.Count;i++)
	{   
		Console.WriteLine("docId is " + JsonDocList[i].GetDocId());
		Console.WriteLine("JsonDoc is " + JsonDocList[i].GetJsonDoc());
	 }  
String 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
                    }
                ]
            }
        }
    }
}
public void FindDocumentsByQueryWithPaging(String dbName, String collectionName, String query, int max, int offset, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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
String dbName = "test";
String collectionName = "foo";
Query q1 = QueryBuilder.build("NickScore", 500, Operator.LESS_THAN_EQUALTO);
Query q2 = QueryBuilder.build("name", "Ni", Operator.LIKE);	
Query q3 = QueryBuilder.compoundOperator(q1, Operator.AND, q2);
int max = 1;
int offset = 0;

storageService.FindDocumentsByQuery(dbName,collectionName,q3,max,offset,requestCallback); /* returns the Storage object. */ 
OnSuccess(Object obj){
Storage storage = (Storage) obj;
Console.WriteLine("dbName is " + storage.GetDbName());
Console.WriteLine("Collection Name is " + storage.GetCollectionName());
IList<Storage.JSONDocument> JsonDocList = storage.GetJsonDocList();  
	for(int i=0;i <JsonDocList.Count;i++)
	{   
		Console.WriteLine("docId is " + JsonDocList[i].GetDocId());
		Console.WriteLine("JsonDoc is " + JsonDocList[i].GetJsonDoc());
	 }  
String 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
                    }
                ]
            }
        }
    }
}
public void FindDocsWithQueryPagingOrderBy(String dbName, String collectionName, int max, int offset, String query, String orderByKey,Stringtype,App42Callback requestCallback)

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
key - Key to be searched for target JSON doc
type - Sorts the document by its type either ASCENDING or DESCENDING
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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
String dbName = "test";
String collectionName = "foo";
Query q1 = QueryBuilder.build("name", "Nick", Operator.EQUALS);	
Query q2 = QueryBuilder.build("company", "shep", Operator.LIKE);	
Query q3 = QueryBuilder.compoundOperator(q1, Operator.AND, q2);		
int max = 1;
int offset = 0;

storageService.FindDocumentsByQuery(dbName,collectionName,q3,max,offset,"_id",OrderByType.ASCENDING,requestCallback); /* returns the Storage object. */ 
OnSuccess(Object obj){
Storage storage = (Storage) obj;
Console.WriteLine("dbName is " + storage.GetDbName());
Console.WriteLine("Collection Name is " + storage.GetCollectionName());
IList<Storage.JSONDocument> JsonDocList = storage.GetJsonDocList();  
	for(int i=0;i <JsonDocList.Count;i++)
	{   
		Console.WriteLine("docId is " + JsonDocList[i].GetDocId());
		Console.WriteLine("JsonDoc is " + JsonDocList[i].GetJsonDoc());
	 }  
String 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"
                    }
                ]
            }
        }
    }
}
public void UpdateDocumentByDocId(String dbName, String collectionName, String docId, String newJsonDoc, App42Callback requestCallback)

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
String dbName = "test";
String collectionName = "foo";
String docId = "4faa4707c68df147a51f8be1";
String newJsonDoc = "{\"employeeName \":\"Gill\"}";	

storageService.UpdateDocumentByDocId(dbName,collectionName,docId,newJsonDoc); /* returns the Storage object. */ 
OnSuccess(Object obj)
{
Storage storage = (Storage) obj;
Console.WriteLine("dbName is " + storage.GetDbName());
Console.WriteLine("Collection Name is " + storage.GetCollectionName());
IList<Storage.JSONDocument> JsonDocList = storage.GetJsonDocList();  
for(int i=0;i <JsonDocList.Count;i++)
{   
   Console.WriteLine("JsonDoc is " + JsonDocList[i].GetJsonDoc()); 
}  
String jsonResponse = storage.ToString(); /* returns the response in JSON format. (as shown below)*/
}
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": {
                    "employeeName": "Gill"
                }
            }
        }
    }
}
public void UpdateDocumentByKeyValue(String dbName, String collectionName, String key, String value, String newJsonDoc, App42Callback requestCallback)

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.
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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
String dbName = "test";
String collectionName = "foo";
String key = "employeeName";
String value = "Nick";
String newJsonDoc = "{\"employeeName \":\"Gill\"}";	

storageService.UpdateDocumentByKeyValue(dbName,collectionName,key,value,newJsonDoc,requestCallback); /* returns the Storage object. */ 
OnSuccess(Object obj){
Storage storage = (Storage) obj;
Console.WriteLine("dbName is " + storage.GetDbName());
Console.WriteLine("Collection Name is " + storage.GetCollectionName());
IList<Storage.JSONDocument> JsonDocList = storage.GetJsonDocList();  
	for(int i=0;i <JsonDocList.Count;i++)
	{   
		Console.WriteLine("docId is " + JsonDocList[i].GetDocId());
		Console.WriteLine("JsonDoc is " + JsonDocList[i].GetJsonDoc()); 
	 }  
String 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"
                    }
                ]
            }
        }
    }
}
public void DeleteDocumentById(String dbName, String collectionName, String docId, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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
String dbName = "test";
String collectionName = "foo";
String docId = "4faa3f1ac68df147a51f8bd7";	

storageService.DeleteDocumentById(dbName, collectionName, docId,requestCallback); /* returns the App42Response object. */
OnSuccess(Object obj){
App42Response response = (App42Response) obj;
Boolean success = response.IsResponseSuccess();
String 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"
                }
            }
        }
    }
}
public void MapReduce(String dbName, String collectionName, String mapFunction, String reduceFunction, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

The target JSON document.

Response: String 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
String dbName = "test";
String collectionName = "foo";
String mapFunction = "function map(){ emit(this.user,1);}";
String reduceFunction = "function reduce(key, val){var sum = 0; for(var n=0;n< val.length;n++){ sum = sum + val[n]; } return sum;}";

storageService.MapReduce(dbName, collectionName, mapFunction, reduceFunction,requestCallback); /* returns the Storage object. */ 
                            
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": [
                    {
                        "_id": null,
                        "value": 2
                    }
                ]
            }
        }
    }
}
public void InsertJsonDocUsingMap(String dbName, String collectionName, Dictionary<String, String> map, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

Storage object

Response: Storage Object

For more details click Exception
String dbName = "test";
String collectionName = "foo";
	Dictionary<String, String> map = new Dictionary<String, String>();
	map.Add("name", "nick");
    map.Add("age", "28");
	
storageService.InsertJsonDocUsingMap(dbName,collectionName,map,requestCallback); /* returns the Storage object. */ 
OnSuccess(Object obj){
Storage storage = (Storage) obj;
Console.WriteLine("dbName is " + storage.GetDbName());
Console.WriteLine("Collection Name is " + storage.GetCollectionName());
String jsonResponse = storage.ToString(); /* returns the response in JSON format. (as shown below)*/
}
                            
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": {
                    "age": "28",
                    "name": "Nick",
                    "_id": {
                        "$oid": "4faa48fcc68df147a51f8be2"
                    }
                }
            }
        }
    }
}