Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

Using Appery Database, checking if a row exists, and do something if so, and something else if not!

How would one go about the above, using the collection, with the minimal amount of network work?

Would this be best as a server side script, with a return ? If so, would I add the script and call it as a function ?

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

Using Appery Database, checking if a row exists, and do something if so, and something else if not!

Hi Addy,

Create a service that checks if this record exists.

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

Using Appery Database, checking if a row exists, and do something if so, and something else if not!

is that using a $exists on a where clause, as it needs to check 3 col's, and then run create, or update depending on the outcome ? What does exist come back with, true/false ?

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

Using Appery Database, checking if a row exists, and do something if so, and something else if not!

Where would I put the $exists in here ?

'{"$and" : [{"statement_id" : "'+getVar("statementID")+'"}, {"user_id" : "'+getVar("user_id")+'"}]}'; ????

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

Using Appery Database, checking if a row exists, and do something if so, and something else if not!

I have this code:

precode
return '{"$and" : [{"statement_id" : "'+getVar("statementID")+'"}, {"user_id" : "'+getVar("user_id")+'"}]}, {"_id" : {"$exists" : false}}';
/code/pre

I get no errors, but i don't get an answer either. Just no properties.

Ideas please !!

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

Using Appery Database, checking if a row exists, and do something if so, and something else if not!

Addy,

Add this code to the parameter 'where':prereturn '{"$and" : [{"statement_id" : "'+localStorage.getItem("statementID")+'"}, {"user_id" : "'+localStorage.getItem("user_id")+'"}]}';/preWhere 'statementID' and 'user_id' are in localStorage.

To check result (true/false) run this code on Success event:prevar result = (data.length 0) ;/pre

Adako
Posts: 0
Joined: Wed Apr 09, 2014 8:46 pm

Using Appery Database, checking if a row exists, and do something if so, and something else if not!

Hello Katya, I cant seem to get this code to work for three variables. This is the code I am trying to implement:

return '{"$and":[{"From":{"$regex":"' + Appery("from_input").val() + '", "$options":"i"}},{"Type":{"$regex":"' +localStorage.getItem("type") + '", "$options":"i"}},{"To":{"$regex":"' + Appery("to_input").val() + '", "$options":"i"}} ]}';

any suggestions

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Using Appery Database, checking if a row exists, and do something if so, and something else if not!

Hello,

Could you specify what exactly doesn't work.
Could you also show us network request/response screenshots from browser network tab.
http://docs.appery.io/documentation/d...

Adako
Posts: 0
Joined: Wed Apr 09, 2014 8:46 pm

Using Appery Database, checking if a row exists, and do something if so, and something else if not!

I have two input variables "from" and 'to" and I also have a nav bar with three item "bus, flight, taxi. This selects the type of transport required.

I have set the localstorage variable "type" to store what ever value the user selects from the navbar. Now I want the search to return all record matching "from", "to" and "type"

The results I am receiving are only matching "from" and "to" seems to completely ignore the type in local storage variable and will return results without regards to the type

Return to “Issues”