Page 1 of 2

How to use server code to check a database and send results to an app?

Posted: Sun Jun 01, 2014 7:06 pm
by adam griffin

How to use server code to check a database and send results to an app? I would like to check two of my collections in server code, Collection A is check for user_ids and saves to a variable or something, Collection B is check with the user_ids found in Collection A to retrieve information from the user_ids of Collection A. There is no pointers. Can someone help me???


How to use server code to check a database and send results to an app?

Posted: Sun Jun 01, 2014 11:44 pm
by Yurii Orishchuk

Hi Adam.

Sorry but currently your question is not clear for us.

Please provide us screen shots about your collections (A and B) and describe on example what you want to do with data in these collections.

Thanks and regards.


How to use server code to check a database and send results to an app?

Posted: Sun Jun 01, 2014 11:52 pm
by adam griffin

Collection A
{User1_Id}{Friend_Id}

Collection B
{Message}{Message_Creater_Id}

I have figured how to check collection A using server code to get all User1_Ids that has the same Friend_Id. I have save those ids into an array. How can I retrieve all of Collection B Messages that Message_Creator_Ids are the same as the User1_Ids that I have saved in the array.


How to use server code to check a database and send results to an app?

Posted: Mon Jun 02, 2014 12:21 am
by Yurii Orishchuk

Adam.

You have two ways to do it:

First(it's recomended to use this way) is "$in" clause:

See details here:
http://devcenter.appery.io/documentat...

Second is "$or" clause:

see details here:
http://devcenter.appery.io/documentat...

Note: you should use one of suggested clauses in the "where" clause.

For example:

1 first way.

precode

//You should replace "20" and "80" values with your stored in your array you have mentioned.
where={"Message_Creater_Id": {"$in": [20,80]}}

/code/pre

2 second way.

precode

//You should replace "20" and "80" values with your stored in your array you have mentioned.
where={"$or": [{"Message_Creater_Id": "20"},{"Message_Creater_Id": "80"}]}

/code/pre

Regards.


How to use server code to check a database and send results to an app?

Posted: Mon Jun 02, 2014 12:49 am
by adam griffin

Is [20,80] an array?


How to use server code to check a database and send results to an app?

Posted: Mon Jun 02, 2014 1:29 am
by adam griffin

var myarray = message_.split(',');

var retrievedInfo = "";

try {

var XHRResponse = XHR.send("GET", "https://api.appery.io/rest/1/db/colle...", {
"headers": {
"X-Appery-Database-Id": "53894b52e4b0889b402e52d2",
"X-Appery-Master-Key": "99daa6b7-ec97-40e4-9fdf-ece663e1b3af"
},
"parameters": {
//"where": '{"User_Id":"'+myarray+'"}'
"where":'{"User_Id": {"$in":"'+ myarray+'"}}'
}
});

var count = XHRResponse.body.length; // how many rows/records were returned?

for (var i=0; i + e.code); //If something goes wrong, error message appears
}


How to use server code to check a database and send results to an app?

Posted: Mon Jun 02, 2014 1:29 am
by adam griffin

for (var i=0; i}


How to use server code to check a database and send results to an app?

Posted: Mon Jun 02, 2014 3:48 am
by Yurii Orishchuk

Adam, do you have any questions?

If so, please describe it.

Regards.


How to use server code to check a database and send results to an app?

Posted: Mon Jun 02, 2014 4:06 am
by adam griffin

I tried pasting my code but for some reason it will not show up. My response will not show up all I get is {message: ""}. I use this "where":'{"User_Id": {"$in":"'+ myarray+'"}}' in my where statement


How to use server code to check a database and send results to an app?

Posted: Mon Jun 02, 2014 5:06 am
by Yurii Orishchuk

Adam.

It's very hard to say what is wrong in your implementation cause of you don't provide us all needed information.

Thus please make screen shots of your service invoking. And what is realy sends to the server(screen shot of "net" tab with this request).

Also please give us your app public link and describe how we can reproduce this issue.

And try to use:

precode

"where":'{"User_Id": {"$in":"' + JSON.stringify(myarray) + '"}}';

/code/pre

instead of:

precode

"where":'{"User_Id": {"$in":"'+ myarray+'"}}'

/code/pre

Regards.