function testparsequery () {
// get a number of items that match a query by example
var w = getParsed("gasParseData").getObjectsByQuery( {customerid:1},{order:'-value'});
//test if it worked, and do something with the results
if (w.isOk() ){
Logger.log( "all is ok"+ JSON.stringify(w.jObject()));
}
else {
throw( "failed to do query:" + w.browser().url() + ":" + w.browser().status() + ":" + w.browser().text());
}
}
The results
[13-11-29 19:16:50:352 GMT] all is ok{"results":[{"customerid":1,"quantity":9,"value":4230,"invoiceid":145,"date":"Sat Aug 10 2013 00:00:00 GMT+0100 (BST)","createdAt":"2013-11-29T17:25:57.655Z","updatedAt":"2013-11-29T17:25:57.655Z","objectId":"ZflFVMnczp"},{"customerid":1,"quantity":10,"value":3900,"invoiceid":246,"date":"7/25/2013","createdAt":"2013-11-29T17:26:00.448Z","updatedAt":"2013-11-29T17:26:00.448Z","objectId":"NgDkL6qg8u"},{"customerid":1,"quantity":3,"value":1560,"invoiceid":151,"date":"5/21/2013","createdAt":"2013-11-29T17:25:57.874Z","updatedAt":"2013-11-29T17:25:57.874Z","objectId":"XDRMUJSbaA"},{"customerid":1,"quantity":2,"value":1050,"invoiceid":175,"date":"8/22/2013","createdAt":"2013-11-29T17:25:58.538Z","updatedAt":"2013-11-29T17:25:58.538Z","objectId":"QjqVyykjip"}]}
Counting objects
You can count total number in the class, or matching a query
function testparseCount () {
// how many records in the class
Logger.log (getParsed("gasParseData").count());
// how many records in the class with given query
Logger.log (getParsed("gasParseCustomers").count({country:"Libya"}));
}
The results
[13-11-29 19:20:51:038 GMT] 308.0
[13-11-29 19:20:51:210 GMT] 1.0
Updating Objects
You can do a query, and update some or all of the fields in the matching objects
function testparseUpdate () {
// get some items by query and change the scheme name to something else
var w = getParsed("gasParseData").batch(true).updateObjects({customerid:39}, {customerid:1}).batch(false);
if (w.isOk() ){
Logger.log( "all is ok"+ JSON.stringify(w.jObject()));
}
else {
throw( "failed to do query:" + w.browser().url() + ":" + w.browser().status() + ":" + w.browser().text());
}
}
For help and more information join our forum, follow the blog or follow me on Twitter