Tim Childs
Posts: 0
Joined: Thu Aug 01, 2013 3:35 am

Return value from database using OR

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

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Return value from database using OR

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

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

Tim Childs
Posts: 0
Joined: Thu Aug 01, 2013 3:35 am

Return value from database using OR

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Return value from database using OR

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

Tim Childs
Posts: 0
Joined: Thu Aug 01, 2013 3:35 am

Return value from database using OR

OR on the weight

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

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

Return value from database using OR

Hi Tim,

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

Tim Childs
Posts: 0
Joined: Thu Aug 01, 2013 3:35 am

Return value from database using OR

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

Oleg Danchenkov
Posts: 0
Joined: Tue Apr 30, 2013 5:51 pm

Return value from database using OR

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

Tim Childs
Posts: 0
Joined: Thu Aug 01, 2013 3:35 am

Return value from database using OR

Perfect. Thank you!

Return to “Issues”