Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Multiple values for "where" in one database query

Could you please make your app link publick and send us that link

Joseph Yeung
Posts: 0
Joined: Tue Aug 14, 2012 7:48 am

Multiple values for "where" in one database query

OK! Am trying it out. Thanks.

Will return soon.

Joseph Yeung
Posts: 0
Joined: Tue Aug 14, 2012 7:48 am

Multiple values for "where" in one database query

Bravo! It works. Thank you, Marina!

Joseph Yeung
Posts: 0
Joined: Tue Aug 14, 2012 7:48 am

Multiple values for "where" in one database query

Thank you, Marina.

Your advice works very well except in one case. Feeling hard to make of it, I conclude the question in four cases:

code
$.ajax ({..
data: encodeURI(whereClause),
/code

CASE 1 works
code
var whereClause = "where={'answer':'A'}&quot
/code

CASE 2 works
code
var whereClause = "where={'answer':{'$in':['A','B']}}&quot
/code

CASE3 also works
code
var whereClause = "where={'_id':'50efd89ee4b0195a923acbb2'}&quot
/code

CASE4 error 500 {"code":"undefined","description":"invalid ObjectId
code
var whereClause = "where={'_id':{'$in':
['50efd89ee4b0195a923acbb2','51026d83e4b0e330589c4770']}}&quot
/code

Why wouldn't CASE 4 work is beyond me. Could it be that the query is too long??

Anyone has any ideas on it?

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

Multiple values for "where" in one database query

Hello,

Looks like any expressions for _id are interpreted as ObjectId, that's why you cannot write expressions for _id

Joseph Yeung
Posts: 0
Joined: Tue Aug 14, 2012 7:48 am

Multiple values for "where" in one database query

Hi,

But how does CASE 3 work, if no expression can be written for _id?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Multiple values for "where" in one database query

In case 3 you just pass _id and in case 4 there are some expressions for _id and as Katya said before they are interpreted as ObjectId (it's a bug)

Joseph Yeung
Posts: 0
Joined: Tue Aug 14, 2012 7:48 am

Multiple values for "where" in one database query

So, do you see any way to get round this bug?

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

Multiple values for "where" in one database query

It needs to be fixed on server side... Seems there is no workaround.

Ryan Rigby
Posts: 0
Joined: Sun Feb 17, 2013 6:57 pm

Multiple values for "where" in one database query

I am having a similar problem with a multiple where clause when creating a database service. For example, I have two tables - 'US_States' and 'Stores'.
On my app I have two input fields, one to select the State (State_Label) and another to enter the store name (Store_Label).

I have linked the two tables by creating a pointer in the Store table that points to the State ID in the state table. So each Store record in the Stores table has a foreign key capturing which State it is in.

Now if I was to write a SQL query that will return all stores matching that store name in that state it would look something like this -
Select Store_Name from US_States, Stores where State_Label = US_States.State_Name AND Store_Label like Stores.Store_Name;

Could you please help in advising how to create a database service which would perform the same query

Return to “Issues”