Page 1 of 1

Query on 2 where statements

Posted: Mon May 12, 2014 4:26 pm
by Bill Clanton

i am trying to find records in my collection that have both the user's id and a photo id in my "likes" collection.

In the collection both photo_id and user_id are pointers. This is the code i've tried without success.

var user_id = localStorage.getItem("user_id");
where={"$and": [{"collName":"Photos","id": value},{"collName":"users","_id": user_id}]}

i think i'm close on the code, but something is obviously wrong.


Query on 2 where statements

Posted: Mon May 12, 2014 5:16 pm
by Evgene Karachevtsev

Hello Bill,

Here is the correct query syntax on pointer value:
http://docs.appery.io/documentation/b...


Query on 2 where statements

Posted: Mon May 12, 2014 6:44 pm
by Bill Clanton

this is my current syntax and it doesn't seem to be working.

var user_id = localStorage.getItem("user_id");

return '{"$and": [{"Photo_id": {"collName":"Photos","id": '+value+'}},{"user_id":{"collName":"users","_id": '+user_id+'}}]}';


Query on 2 where statements

Posted: Mon May 12, 2014 7:04 pm
by Evgene Karachevtsev

Are there any errors in the browser console?


Query on 2 where statements

Posted: Mon May 12, 2014 11:17 pm
by Bill Clanton

looking in the console did show me that i had some 400 errors on the api.

But after much trial and error, the following code successfully works. This is being used as a way to see if a user has liked a photo or not. So the user id and the photo id are stored locally. Temp is just a spot where i am storing the id of the like record which then gives me either a number or a blank variable, by which i run my conditional statement. The code below is what I send to the query to check if the record exists. So here it is...

localStorage.setItem("temp", "");
var user_id = localStorage.getItem("user_id");
var unique_photo = localStorage.getItem("photo_unique_id");

return '{"$and": [{"Photo_id": {"collName":"Photos","id":"' + value + '"}},{"user_id":{"collName":"users","_id": "' + user_id + '"}}]}';


Query on 2 where statements

Posted: Tue May 13, 2014 3:16 pm
by Bill Clanton

FYI, i am trying to run several queries and also run create services, and several of them suddenly just started giving me internal server errors (500). For them all to break at once leads me to think the problem is on your end.


Query on 2 where statements

Posted: Tue May 13, 2014 5:12 pm
by Evgene Karachevtsev

Hello Bill,

Do you still get this error? Please provide a public link to your app and steps to reproduce the error.