Page 1 of 1

Return value from database using OR

Posted: Fri Aug 02, 2013 9:05 pm
by Tim Childs

Hi,

I have a query service setup to an apery database and I am returning a value using:

return '{ $and: [ { "weight": "'+value+'" }, { "rank": "C" } ] }';

This works, but I also want to include a second OR argument for weight

i.e. return where weight = +value+ OR weight = localVar

I just do not know the correct syntax. Something like:

return '{ $and: [ { "weight": "'+value+'" OR localStorage.getItem("localVarName") }, { "rank": "C" } ] }';

Does anyone know the correct syntax?

Cheers,
Tim


Return value from database using OR

Posted: Fri Aug 02, 2013 10:20 pm
by maxkatz

You need to define 'where' query that looks like this:

code
where={"$or":[{"weight":{"$gt":10}},{"weight":{"$lt":100}}]}
/code


Return value from database using OR

Posted: Fri Aug 02, 2013 10:25 pm
by Tim Childs

I don't understand how that would work with my current code:

return '{ $and: [ { "weight": "'+value+'" }, { "rank": "C" } ] }';

I'm passing in +value+ but the second value will be a local variable.


Return value from database using OR

Posted: Fri Aug 02, 2013 10:34 pm
by maxkatz

Didn't you want to use OR (in subject)?


Return value from database using OR

Posted: Sat Aug 03, 2013 12:04 am
by Tim Childs

OR on the weight

i.e. return name WHERE ( (weight = heavy OR light) AND rank = C)


Return value from database using OR

Posted: Mon Aug 05, 2013 6:48 am
by Kateryna Grynko

Hi Tim,

Please use the following code:
precode{
$and: [{
rank: "value... C"
}, {
$or: [{
weight: "heavy..."
}, {
weight: "light..."
}]
}]
}/code/prePlace this code in one line.


Return value from database using OR

Posted: Wed Aug 07, 2013 7:34 pm
by Tim Childs

Hi Katya,

I tried the following but it just makes my app hang - maybe the syntax is incorrect?

return '{ $and: [{ rank: "C" }, { $or: [ { weight: "'+value+'" }, { weight: "'localStorage.getItem("weight2")'" }] }] }';

The following works OK:

return '{ $and: [ { "weight": "'+value+'" }, { "rank": "C" } ] }';

Many Thanks,
Tim


Return value from database using OR

Posted: Wed Aug 07, 2013 7:59 pm
by Oleg Danchenkov

Try this
return '{ $and: [{ "rank": "C" }, { $or: [ { "weight": "'+value+'" }, { "weight": "' + localStorage.getItem("weight2") + '" }] }] }';


Return value from database using OR

Posted: Wed Aug 07, 2013 9:46 pm
by Tim Childs

Perfect. Thank you!