Bill Clanton
Posts: 0
Joined: Wed Apr 23, 2014 2:48 pm

Query on 2 where statements

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.

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Query on 2 where statements

Hello Bill,

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

Bill Clanton
Posts: 0
Joined: Wed Apr 23, 2014 2:48 pm

Query on 2 where statements

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+'}}]}';

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Query on 2 where statements

Are there any errors in the browser console?

Bill Clanton
Posts: 0
Joined: Wed Apr 23, 2014 2:48 pm

Query on 2 where statements

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 + '"}}]}';

Bill Clanton
Posts: 0
Joined: Wed Apr 23, 2014 2:48 pm

Query on 2 where statements

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.

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Query on 2 where statements

Hello Bill,

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

Return to “Issues”