Page 1 of 1

How to use the "Where" clause in a distinct query

Posted: Wed Jun 26, 2013 2:03 am
by Greg5988649

Hi,

I'm building an app with nested lists (on separate pages). Each list needs to be a distinct list, restricted further by the items chosen in the earlier lists.

I can achieve a distinct list via the REST service but can't seem to get the "Where" clause working - either with a defined value or a local storage variable. It works when testing the service but not with mapping. I assume the answer lies with JavaScript but I can't figure it out.

My DB collection has the fields, OriginPort, DestinationPort, CntrType, Rate.
Here is the process flow:
1) I list distinct OriginPort.
2) The user clicks an item on the list and a local storage variable, originVB, is created.
3) Navigate to next page/list where I list distinct DestinationPort where OriginPort = originVB. This is where it fails and nothing is listed.

The local storage variable is definitely being set. The JS console in Chrome is showing "400 Bad Request".

I'm using the following JS in the "Where" request parameter:
var value1 = localStorage.getItem('originVB');
return '{"OriginPort":"'+value1+'"}';

Please help!


How to use the "Where" clause in a distinct query

Posted: Wed Jun 26, 2013 2:33 am
by maxkatz

Use Chrome Dev. Tools Network tab to see the actual request that's being sent.


How to use the "Where" clause in a distinct query

Posted: Wed Jun 26, 2013 4:17 am
by Greg5988649

Hi Max

Thanks for your reply. Here is the request. It all seems OK to me but hopefully your trained eye will pick something obvious up:

Request URL:https://api.appery.io/rest/1/db/colle...
Request Method:POST
Status Code:400 Bad Request
Request Headersview source
Accept:application/json, text/javascript, /; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Connection:keep-alive
Content-Length:38
Content-Type:application/json
Host:api.appery.io
Origin:http://appery.io
Referer:http://appery.io/app/view/eb22e6f3-e6...
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36
X-Appery-Database-Id:51a28f54e4b00afed5f89e41
Request Payloadview source
{where:{"OriginPort":"Bluff"}}
where: "{"OriginPort":"Bluff"}"
Response Headersview source
Access-Control-Allow-Origin:http://appery.io
Connection:keep-alive
Content-Type:application/json
Date:Wed, 26 Jun 2013 04:15:39 GMT
Server:nginx
Transfer-Encoding:chunked


How to use the "Where" clause in a distinct query

Posted: Wed Jun 26, 2013 5:04 am
by Greg5988649

Further to the above, note that "Bluff" was selected from the first list and appears to have come through correctly to the JS from the local storage variable.


How to use the "Where" clause in a distinct query

Posted: Wed Jun 26, 2013 12:18 pm
by Anton Artyukh5836028

Hi Greg,

I don't see in your request headers X-Appery-Session-Token.
Do you have any authorization actions?


How to use the "Where" clause in a distinct query

Posted: Wed Jun 26, 2013 10:52 pm
by Greg5988649

Hi Anton

I wasn't but have now included a login page and session token:

Request URL:https://api.appery.io/rest/1/db/colle...
Request Method:POST
Status Code:400 Bad Request
Request Headersview source
Accept:application/json, text/javascript, /; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Connection:keep-alive
Content-Length:39
Content-Type:application/json
Host:api.appery.io
Origin:http://appery.io
Referer:http://appery.io/app/view/eb22e6f3-e6...
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36
X-Appery-Database-Id:51a28f54e4b00afed5f89e41
X-Appery-Session-Token:4f2df0c9-afc6-4712-be76-14042ba358dc
Request Payloadview source
{where:{"OriginPort":"Nelson"}}
where: "{"OriginPort":"Nelson"}"
Response Headersview source
Access-Control-Allow-Origin:http://appery.io
Connection:keep-alive
Content-Type:application/json
Date:Wed, 26 Jun 2013 22:49:26 GMT
Server:nginx
Transfer-Encoding:chunked


How to use the "Where" clause in a distinct query

Posted: Thu Jun 27, 2013 3:09 pm
by Maryna Brodina

Hello! There was an error in docs. Please use POST method instead of GET. Also replace code codevar value1 = localStorage.getItem('originVB');
return '{"OriginPort":"'+value1+'"}'; /code with the following codevar value1 = localStorage.getItem('originVB');
return {"OriginPort": value1 }; //return object, not a string/code


How to use the "Where" clause in a distinct query

Posted: Fri Jun 28, 2013 1:54 am
by Greg5988649

Excellent! Thanks Marina.
I was already using the POST method but it was the error in the JS that you pointed out. Such a silly mistake but thanks so much for finding it :-)


How to use the "Where" clause in a distinct query

Posted: Sat Mar 21, 2015 2:48 pm
by EJLD

Hi There, I am facing the same kind of issue:
. the distinct query is set on the field "receiver",
. and I would like to filter using a criteria from a different field, the "sender".
I am testing in where : {"sender":"EJLD"}
so far, it is not taken into account.
still I get the same set of data as response.
Any advice ?
Thk you in advance,
Eric