Page 1 of 1

Multiple where clause from 2 localstorage variables

Posted: Wed Mar 25, 2015 10:51 am
by Sander

Hi,

First of all thank you for your great product; although I'm relatively new to all this, I'm making great progress on my project.

I'm running into something that's beyond me though. My app is supposed to register how much water I drink each day, which it does nicely. Only I can't get it to only display today's results in a feedback page. It is possible to display all results belonging to one user, using a single where-clause: return "{'user':{'$regex':'(?i)."+ value +".'}}";

However, I cant' get the app to display only today's results using a multiple where clause, which looks something like:
return "{'$and':[{'user':{'$regex':'(?i).'"+ value +"'.'}},{'date': {'$regex':'(?i).'"+ Apperyio.storage.todaysdate.get() +"'.'}}]}";

The storage variable todaysdate is tested and populated with today's date; writes to the database alright to column 'date'. So that should all be alright...

Any tips?
Thank you very much in advance,
best,

Sander


Multiple where clause from 2 localstorage variables

Posted: Wed Mar 25, 2015 3:23 pm
by Bruce Stuart

Sander,

Just a thought - but the best way to debug a where clause - is to use it in the builder - in your service - enter the where clause you have above (of course you have to enter a date by hand)..... keep trying different combinations until you get it right here.

As another aside - when I do my date queries - I always bound them by a less than or equal to or greater than or equal to - in order to get a day or a series of days to come back. The regex expression on dates may be less efficient also in case you want to index that field for future use.

Image


Multiple where clause from 2 localstorage variables

Posted: Wed Mar 25, 2015 4:28 pm
by Bruce Stuart

also - here's a where clause where I'm accomplishing something similar to what you are trying to do - that does successfully bring back results (just extracted it from my console log --- I log all my where clauses for debugging purposes...)

{'$and': [{ "suserid":"54da3459e4b0e533414b614f", 'sstatus':'U' , 'dutcdatetimetosend': {$gte : '2015-03-25 16:26:21.278', $lte : '2015-04-01 16:26:21.278' } }]}


Multiple where clause from 2 localstorage variables

Posted: Thu Mar 26, 2015 10:13 am
by Sander

Hi Bruce,

Thank you for your helpful response. In the end, it turned out that I only needed to supply today's date for the where clause; somehow, the user id is superfluous. That surprises me, because when I try to list all entries made by a single user, I do need the user Id as an argument. Odd, but it works.

The $gte comment was very helpful, because my next task is to display yesterday's results. That should not be very hard now.

Best,
Sander


Multiple where clause from 2 localstorage variables

Posted: Thu Mar 26, 2015 6:12 pm
by Bruce Stuart

Awesome - Hope the app your building gets great traction. Good luck!