Robert Larsen
Posts: 0
Joined: Fri Aug 02, 2013 6:56 am

Read Database

In reference to above. When I was trying to map the local storage variable to the where request for the query service. You corrected me though in adding JS to the event success so the server response would create and array of all the keys to local storage variable. What I am trying to store in local storage variable though is an array of keys that are provided through the server response. Now I want to send those keys back to query service, and grab there respective data columns, from the database, and then map those values to the page. But I don't know if I need JS on the where parameter of the query to sort the array from the local storage variable. ( Is the where request parameter) or the ( Query Service) capable of processing one Unique Id or string or multiple?

Did this clarify, please let me know.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Read Database

Hello! Sorry for delay. Not sure I completely understand what are you going to do. Anyway you can do prelocalStorage.setItem("event_id", JSON.stringify(event_id));/pre instead prelocalStorage.setItem("event_id", event_id);/preIn this case you'll be able to restore event_id array from localStorage any time you need. To restore data from localStorage use code prevar event_id;
try {
event_id = JSON.parse(localStorage.getItem("event_id"));
if ({}.toString.call(event_id) !== "[object Array]") {
event_id = [];
}
} catch ( e ) {
event_id = [];
}/preAdd necessary code in mapping to where parameter. More information about requests to DB is here http://docs.appery.io/documentation/b...

Robert Larsen
Posts: 0
Joined: Fri Aug 02, 2013 6:56 am

Read Database

I am trying to create an event tracker. As you can see in my screenshots below. You will select a world (server) and a map. The selections are saved to their own local storage variables, and clicking on submit will be directed to the next page. Ignore everything under the first submit button. This next page is where I am trying to show the status of current events for the previous selections. So now on page load a rest service is called that takes the selections that where saved to local storage variables and inputs them into a request parameter now on service response I am sent back a list of event ids. Now these ID's I am saving under my local storage variable Event_ID. You have provided me code to save them into an array. Now this is my hangup, I have an entire database of these event_ids now I need to send, or search my database for these exact 8 event ids and grab information from a corresponding field. In this case EventName and then list it back to the page, under a label or list field. I added the code you provided to the where response.

var event_id;
try {
event_id = JSON.parse(localStorage.getItem("event_id"));
if ({}.toString.call(event_id) !== "[object Array]") {
event_id = [];
}
} catch ( e ) {
event_id = [];
}

I am not sure that is right....? I now get a list of all events in my database. What I am trying to figure out is how to send these unique event ids back to the database whether through, query, read, I am not sure I am assuming query is the best solution here. My issue is can the query handle 8 unique ids or would it be necessary to call the service 8 separate times to handle the information. Or am I going about this process all wrong. Because depending on the server map selection you may have x amount of keys to pull information from the database. Image Imageinline.png?1391911326[/img] [/url]

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Read Database

Hi Robert,

You can use such a comparison value in parameter 'where': code$in/code http://docs.appery.io/documentation/b...

Robert Larsen
Posts: 0
Joined: Fri Aug 02, 2013 6:56 am

Read Database

How would this work using $in curl. When the value can always change?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Read Database

Hello!
Should be something like this prevar event_id;
try {
event_id = JSON.parse(localStorage.getItem("event_id"));
if ({}.toString.call(event_id) !== "[object Array]") {
event_id = [];
}
} catch ( e ) {
event_id = [];
}
return '{"_id": {"$in": ' + JSON.stringify(event_id ) + '}}';/pre

Return to “Issues”