App42 Cloud API

Ruby 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 = App42::ServiceAPI.new("<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 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.insert_json_document(dbName,collectionName,json); /* returns the Storage object. */ 
storage = storageService.insertJSONDocument(dbName,collectionName,json); /* returns the Storage object. */
puts "dbName is #{storage.dbName}";
puts "collectionName is #{storage.collectionName}" ;
jsonDocList = Array.new
jsonDocList = storage.getJsonDocList();
for jsonDoc in jsonDocList
  puts "docId is #{jsonDoc.docId}";
  puts "JsonDoc is #{jsonDoc.jsonDoc}";
end
jsonResponse = storage.to_s(); /* 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";	
						
begin
  storage = storageService.find_document_by_id(dbName, collectionName, docId);
rescue App42Exception => ex
  appErrorCode = ex.app_error_code;
  httpErrorCode = ex.http_error_code;

  if(appErrorCode == 2600)
    # Handle here for Not Found (Document by the Id '<docId>' does not exist.)

  elsif(appErrorCode  == 2606)
    #Handle here for Bad Request (Document Id '<docId>' is not valid.)

  elsif(appErrorCode == 1401)
    #handle here for Client is not authorized

  else(appErrorCode == 1500)
    #handle here for Internal Server Error
  end

  jsonText = ex.detailMessage(); /* returns the Exception text in JSON format. (as shown below)*/
end
	{
	   "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.

def insert_json_document(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:

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";
json = "{\"employeeName \":\"Nick\"}";
						
storage = storageService.insert_json_document(dbName,collectionName,json); /* returns the Storage object. */
puts "dbName is #{storage.dbName}";
puts "collectionName is #{storage.collectionName}" ;
jsonDocList = Array.new();
jsonDocList = storage.getJsonDocList();
for jsonDoc in jsonDocList do
  puts "docId is #{jsonDoc.docId}";
  puts "jsonDoc is #{jsonDoc.jsonDoc}";
end
jsonResponse = storage.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": {
                    "employeeName": "Nick",
                    "_id": {
                        "$oid": "4faa3f1ac68df147a51f8bd7"
                    }
                }
            }
        }
    }
}
def find_all_documents(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:

The method throws the following exception with the error code
/*
2602 - NOT FOUND - No document in the collection '<collectionName>' exists. 	
*/
For more details click Exception
dbName = "test";
collectionName = "foo";
						
storage = storageService.find_all_documents(dbName,collectionName); /* returns the Storage object. */
puts "dbName is #{storage.dbName}";
puts "collectionName is #{storage.collectionName}";
jsonDocList = Array.new();
jsonDocList = storage.getJsonDocList();
for jsonDoc in jsonDocList do
  puts "docId is #{jsonDoc.docId}";
  puts "jsonDoc is #{jsonDoc.jsonDoc}";
end
jsonResponse = storage.to_s(); /* 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"
                    }
                ]
            }
        }
    }
}
def find_all_documents_count(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

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

response = storage.find_all_documents_count(dbName,collectionName); /* returns the App42Response objects. */
success = response.isResponseSuccess();
jsonResponse = response.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "totalRecords": 96
        }
    }
}
def find_all_documents_by_paging(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: Storage Object

Exception:

The method throws the following exception with the error code
/*
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.find_all_documents_by_paging(dbName,collectionName,max,offset); /* returns the Storage object. */
puts "dbName is #{storage.dbName}";
puts "Collection Name is #{storage.collectionName}";
jsonDocList = Array.new();
jsonDocList = storage.jsonDocList();
for jsonDoc in jsonDocList do
  puts "docId is #{jsonDoc.docId}";
  puts "JsonDoc is #{jsonDoc.jsonDoc}";
end
jsonResponse = storage.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": [
                    {
                        "_id": {
                            "$oid": "4faa3f1ac68df147a51f8bd7"
                        },
                        "employeeName": "Nick"
                    }
                ]
            }
        }
    }
}
def find_document_by_id(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:

The method throws the following exception with the error code
/*
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.find_document_by_id(dbName,collectionName,docId); /* returns the Storage object. */
puts "dbName is #{storage.dbName}";
puts "collectionName is #{storage.collectionName}";
jsonDocList = Array.new();
jsonDocList = storage.jsonDocList();
for jsonDoc in jsonDocList do
  puts "docId is #{jsonDoc.docId}";
  puts "jsonDoc is #{jsonDoc.jsonDoc}";
end
jsonResponse = storage.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": {
                    "_id": {
                        "$oid": "50471017c68d8e2fae756545"
                    },
                    "employeeName": "Nick"
                }
            }
        }
    }
}
def find_document_by_key_value(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:

The method throws the following exception with the error code
/*
2601 - NOT FOUND - Document by key '<key>' and value '<value>' does not exist.
*/
For more details click Exception
dbName = "test";
collectionName = "foo";
key = "foo";
value = "30July";
						
storage = storageService.find_document_by_key_value(dbName,collectionName,key,value); /* returns the Storage object. */
puts "dbName is #{storage.dbName}";
puts "collectionName is #{storage.collectionName}";
jsonDocList = Array.new();
jsonDocList = storage.jsonDocList();
for jsonDoc in jsonDocList do
  puts "docId is #{jsonDoc.docId}";
  puts "jsonDoc is #{jsonDoc.jsonDoc}";
end
jsonResponse = storage.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": {
                    "employeeName": "Nick",
                    "_id": {
                        "$oid": "50470f5fc68d8e2fae756544"
                    }
                }
            }
        }
    }
}
def update_document_by_key_value(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:

The method throws the following exception with the error code
/*
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 = "date";
value = "31jan";
newJsonDoc = "{'new31jan123' : 'new31jan'}";
							
storage = storageService.update_document_by_key_value(dbName,collectionName,key,value,newJsonDoc); /* returns the Storage object. */
puts "dbName is #{storage.dbName}";
puts "collectionName is #{storage.collectionName}";
jsonDocList = Array.new();
jsonDocList = storage.jsonDocList();
for jsonDoc in jsonDocList do
  puts "docId is #{jsonDoc.docId}";
  puts "jsonDoc is #{jsonDoc.jsonDoc}";
end
jsonResponse = storage.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": [
                    {
                        "_id": {
                            "$oid": "4fb0dc0bc68d13dfac87d37a"
                        },
                        "employeeName": "Gill"
                    }
                ]
            }
        }
    }
}
def update_document_by_doc_id(dbName, collectionName, docId, newJsonDoc)

Update target document using document ID 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
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";
value = "31jan";
newJsonDoc = "{'new31jan123' : 'new31jan'}";
							
storage = storageService.update_document_by_doc_id(dbName,collectionName,docId,newJsonDoc); /* returns the Storage object. */
puts "dbName is #{storage.dbName}";
puts "collectionName is #{storage.collectionName}";
jsonDocList = Array.new();
jsonDocList = storage.jsonDocList();
for jsonDoc in jsonDocList do
  puts "docId is #{jsonDoc.docId}";
  puts "jsonDoc is #{jsonDoc.jsonDoc}";
end
jsonResponse = storage.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": {
                    "employeeName": "Gill"
                }
            }
        }
    }
}
def delete_document_by_id(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:

The method throws the following exception with the error code
/*
2600 - NOT FOUND - Document by the Id '<docId>' does not exist. 
*/
For more details click Exception
dbName = "test";
collectionName = "foo";
docId = "4faa4b6cc68df147a51f8be3";
						
response = storageService.delete_document_by_id(dbName, collectionName, docId); /* returns the App42Response object. */
success = response.isResponseSuccess();
jsonResponse = response.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": {
                    "_id": {
                        "$oid": "4faa3f1ac68df147a51f8bd7"
                    },
                    "employeeName": "Nick"
                }
            }
        }
    }
}
def map_reduce(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: String Object

Exception:

The method throws the following exception with the error code
/*
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.map_reduce(dbName, collectionName, mapFunction, reduceFunction); /* returns the Storage object. */ 
jsonResponse = response.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "storage": {
                "dbName": "test",
                "collectionName": "foo",
                "jsonDoc": [
                    {
                        "_id": null,
                        "value": 2
                    }
                ]
            }
        }
    }
}
def insert_json_doc_using_map(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";
map = Hash.new();
map.store("name", "nick");
map.store("age", "28");
						
storage = storageService.insert_json_doc_using_map(dbName,collectionName,map); /* returns the Storage object. */   
puts "dbName is #{storage.dbName}";
puts "collectionName is #{storage.collectionName}"  ;
jsonResponse = storage.to_s(); /* 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"
                    }
                }
            }
        }
    }
}
def find_document_by_query(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";
op = App42::Storage::QueryBuilder::Operator.new();
qb = App42::Storage::QueryBuilder.new();
q1 = qb.build("NickScore", 300, op.enum("LESS_THAN_EQUALTO"));
						
storage = storageService.find_documents_by_query(dbName, collectionName, q1); /* returns the Storage object. */
puts  "dbName is #{storage.dbName}";
puts  "Collection Name is #{storage.collectionName}";
jsonDocList = Array.new();
jsonDocList = storage.jsonDocList();

for jsonDoc in jsonDocList
  puts "docId is #{jsonDoc.docId}";
  puts  "JsonDoc is #{jsonDoc.jsonDoc}";
end

jsonResponse = storage.to_s(); /* 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
                    }
                ]
            }
        }
    }
} 
def find_document_by_query(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";
op = App42::Storage::QueryBuilder::Operator.new();
qb = App42::Storage::QueryBuilder.new();
q1 = qb.build("NickScore", 300, op.enum("LESS_THAN_EQUALTO"));
q2 = qb.build("name", "shephertz", op.enum("LIKE"));	
q3 = qb.compoundOperator(q1, op.enum("AND"), q2);		
						
storage = storageService.find_documents_by_query(dbName, collectionName, q3); /* returns the Storage object. */
puts  "dbName is #{storage.dbName}";
puts  "Collection Name is #{storage.collectionName}";
jsonDocList = Array.new();
jsonDocList = storage.jsonDocList();

for jsonDoc in jsonDocList
  puts "docId is #{jsonDoc.docId}";
  puts  "JsonDoc is #{jsonDoc.jsonDoc}";
end

jsonResponse = storage.to_s(); /* 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
                    }
                ]
            }
        }
    }
} 
def find_document_by_query(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";
op = App42::Storage::QueryBuilder::Operator.new();
qb = App42::Storage::QueryBuilder.new();
q1 = qb.build("NickScore", 300, op.enum("LESS_THAN_EQUALTO"));
q2 = qb.build("name", "", op.enum("LIKE"));	
q3 = qb.compoundOperator(q1, op.enum("AND"), q2);		
						
storage = storageService.find_documents_by_query(dbName, collectionName, q3); /* returns the Storage object. */
puts  "dbName is #{storage.dbName}";
puts  "Collection Name is #{storage.collectionName}";
jsonDocList = Array.new();
jsonDocList = storage.jsonDocList();

for jsonDoc in jsonDocList
  puts "docId is #{jsonDoc.docId}";
  puts  "JsonDoc is #{jsonDoc.jsonDoc}";
end

jsonResponse = storage.to_s(); /* 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
                    }
                ]
            }
        }
    }
}  
def find_document_by_query_with_paging(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";
op = App42::Storage::QueryBuilder::Operator.new();
qb = App42::Storage::QueryBuilder.new();
q1 = qb.build("NickScore", 300, op.enum("LESS_THAN_EQUALTO"));
q2 = qb.build("name", "Ni", op.enum("LIKE"));	
q3 = qb.compoundOperator(q1, op.enum("AND"), q2);		
int max = 1;
int offset = 0;
						
storage = storageService.find_documents_by_query_with_paging(dbName, collectionName, q3, max, offset); /* returns the Storage object. */
puts  "dbName is #{storage.dbName}";
puts  "Collection Name is #{storage.collectionName}";
jsonDocList = Array.new();
jsonDocList = storage.jsonDocList();

for jsonDoc in jsonDocList
  puts "docId is #{jsonDoc.docId}";
  puts  "JsonDoc is #{jsonDoc.jsonDoc}";
end

jsonResponse = storage.to_s(); /* 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"
                    }
                ]
            }
        }
    }
}  
def find_docs_with_query_paging_order_by(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:

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";
op = App42::Storage::QueryBuilder::Operator.new();
qb = App42::Storage::QueryBuilder.new();
q1 = qb.build("name", "Nick", op.enum("EQUALS"));
q2 = qb.build("company", "shep", op.enum("LIKE"));	
q3 = qb.compoundOperator(q1, op.enum("AND"), q2);		
int max = 1;
int offset = 0;
	
order = App42::Storage::OrderByType.new();	
storage = storageService.find_docs_with_query_paging_order_by(dbName, collectionName, q3, max, offset, "_id", order.enum("ASCENDING")); /* returns the Storage object. */
puts  "dbName is #{storage.dbName}";
puts  "Collection Name is #{storage.collectionName}";
jsonDocList = Array.new();
jsonDocList = storage.jsonDocList();

for jsonDoc in jsonDocList
  puts "docId is #{jsonDoc.docId}";
  puts  "JsonDoc is #{jsonDoc.jsonDoc}";
end

jsonResponse = storage.to_s(); /* 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
                    }
                ]
            }
        }
    }
}