Page 1 of 5

How to use search to query multiple database columns

Posted: Wed Mar 05, 2014 4:04 pm
by mymojo

Hi there!

I've been going through the tutorial and I have figured out how to search and return values from a database collection, but I'd like to be able to search any column. I can only figure out how to search one column (as that's all the tutorials provide as examples). How would I search all columns in the table and return information for a row that has the searched term in any column?

I need to replace the "Product" (the column being searched) in the following line with a value that will search any column, not just the product column.

return '{"Product":{"$regex":"^'+value+'", "$options":"i"}}';

Thanks in advance!


How to use search to query multiple database columns

Posted: Wed Mar 05, 2014 4:40 pm
by mymojo

I'd also like it to search any of the words in the columns, not just the first word. So if the column cell has "Red Fire Truck" in it, searching for Red, Fire, or Truck would all return that row's data.


How to use search to query multiple database columns

Posted: Wed Mar 05, 2014 5:17 pm
by Maryna Brodina

Hello! Please take a look here http://docs.appery.io/documentation/b... (Multiple where clauses)


How to use search to query multiple database columns

Posted: Wed Mar 05, 2014 5:24 pm
by mymojo

This is as close as I can get, but it currently returns nothing.

return '{"$or":[{"Product":{"$regex":"^'+value+'", "$options":"i"},{"Company":{"$regex":"^'+value+'", "$options":"i"}]}';


How to use search to query multiple database columns

Posted: Wed Mar 05, 2014 5:46 pm
by mymojo

So I use a curl command? Can you provide an example for me that would fit my situation?


How to use search to query multiple database columns

Posted: Wed Mar 05, 2014 5:48 pm
by mymojo

I tried the $or, but it's not returning what's searched for. Can you tell me what is wrong with my syntax?

return '{"$or":[{"Product":{"$regex":"^'+value+'", "$options":"i"},{"Company":{"$regex":"^'+value+'", "$options":"i"}]}';


How to use search to query multiple database columns

Posted: Wed Mar 05, 2014 6:00 pm
by mymojo

Ok great, I got it with the following code:

return '{"$or":[{"Product":{"$regex":"^'+value+'", "$options":"i"}},{"Company":{"$regex":"^'+value+'", "$options":"i"}}]}';

One more question. How do I get it to return results based on any word in the cell, not just the first one?


How to use search to query multiple database columns

Posted: Wed Mar 05, 2014 6:05 pm
by mymojo

Do I use $in? And if so, how?


How to use search to query multiple database columns

Posted: Wed Mar 05, 2014 6:22 pm
by Maryna Brodina

Please take a look here https://getsatisfaction.com/apperyio/... and let us know if it helps


How to use search to query multiple database columns

Posted: Wed Mar 05, 2014 8:20 pm
by mymojo

Thank you!