Page 1 of 1

What is wrong with how I have combined two where clauses?

Posted: Tue Jan 12, 2016 8:29 pm
by Logan Wells

Hi,
I am having problems combining two where clauses:

I am trying to combine these clauses:
1.
var useridexpensevar = localStorage.getItem("useridexpense");
var whereObject = {"userprofid": {"$inQuery": {_id: useridexpensevar } //}};
return JSON.stringify(whereObject);

2.
var staridvar = localStorage.getItem("starid");
var whereObject = {"starid": {"$inQuery": {_id: staridvar } }};
return JSON.stringify(whereObject);

And this is what I have made:
var useridexpensevar = localStorage.getItem('useridexpense'), star = localStorage.getItem('starid');
var whereObject = {"userprofid": {"$inQuery": {id: useridexpensevar } } + {"starid": {"$inQuery": {id: star } } }};
return JSON.stringify(whereObject);

What is wrong with it? There are no JS issues int he console or any red flags when I put the code in.

Thanks


What is wrong with how I have combined two where clauses?

Posted: Tue Jan 12, 2016 8:56 pm
by asid

This is an example how I did it, not sure if this helps, I separated with a comma.

var whereClause = { "region": localStorage.getItem("myRegion"),
"menuItem": localStorage.getItem("mySubMenuItem")};
return JSON.stringify(whereClause);


What is wrong with how I have combined two where clauses?

Posted: Tue Jan 12, 2016 9:42 pm
by Serhii Kulibaba

Hello,

Please look at our documentation for queries like that: https://devcenter.appery.io/documenta...


What is wrong with how I have combined two where clauses?

Posted: Tue Jan 12, 2016 11:15 pm
by Logan Wells

Aren't I doing the same thing with the $and but with a '+' sign, if I use the $and it comes up with errors.


What is wrong with how I have combined two where clauses?

Posted: Wed Jan 13, 2016 10:21 am
by Illya Stepanov

Hi Logan - Could you please show us your full where query string that you are using?


What is wrong with how I have combined two where clauses?

Posted: Wed Jan 13, 2016 11:16 am
by Logan Wells

The one labeled 'And this is what I have made: ' is the full string we are using.


What is wrong with how I have combined two where clauses?

Posted: Wed Jan 13, 2016 11:31 am
by Illya Stepanov

Sorry, I don't see anything - could you please repeat.


What is wrong with how I have combined two where clauses?

Posted: Wed Jan 13, 2016 11:48 am
by Logan Wells

Alright, my bad:
var useridexpensevar = localStorage.getItem('useridexpense'), star = localStorage.getItem('starid');
var whereObject = {"userprofid": {"$inQuery": {id: useridexpensevar } } + {"starid": {"$inQuery": {id: star } } }};
return JSON.stringify(whereObject);

Thanks


What is wrong with how I have combined two where clauses?

Posted: Fri Jan 15, 2016 4:07 pm
by Serhii Kulibaba

Logan, please use:

prereturn '{"$and":[{"userprofid": {"$inQuery": {"id": "'+useridexpensevar+'" } }}, {"starid": {"$inQuery": {"id": "'+star+'"}}}]}';/pre
instead of:

prevar whereObject = {"userprofid": {"$inQuery": {id: useridexpensevar } } + {"starid": {"$inQuery": {id: star } } }};
return JSON.stringify(whereObject); /pre


What is wrong with how I have combined two where clauses?

Posted: Sat Jan 16, 2016 3:42 pm
by Logan Wells

Thanks so much! This was perfect