Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

Using $in to find a word or words issue

I am unable to find how $in works. Here is my code

precode
$.ajax({
type: 'GET',
beforeSend: function(request) {
request.setRequestHeader('X-Appery-Database-Id', 'dv_id');
},
url: 'https://api.appery.io/rest/1/db/collections/questions/',
dataType: 'json',
data: {
where: '{"question": {"$in" : ["'+searchtext+'"]}}',
sort: "-_createdAt"
},
/code/pre

This brings back data. But, say the data in the collection column has:

test
this is a test
I am testing
does testing work

and you search test, it only brings back the first 'test'! $in means contains, so why is it not bringing the rest ?

Thanks

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Using $in to find a word or words issue

You could find how to use $in in this doc: http://docs.appery.io/documentation/b...
Try to test $in with static value.

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

Using $in to find a word or words issue

As I am sure you noticed, I had read that already, otherwise I would not have known about '$in'. Even if i try it with a static value, how would that help in a dynamic value ?

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

Using $in to find a word or words issue

Even with a static 'word', it still only brings back rows with the column equal to 'test' and not containing.

Please advise ?

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Using $in to find a word or words issue

Dear Addy,

This is a simple example to understand how $in works:

Lets assume we have a table with just two collumns - "id" and "name"
and our goal is to get rows with ids: 1, 4 and 6.

for this goal we have to write next "where" structure:

pre"where": {"id": {"$in" : ["1", "4", "6"]} }/pre
-- this filter return only items with id 1, 4 and 6.

But you have a problem with searching by content and $in will not help here.
For your goals you have to use regex.

For example:
pre"where": {"name": {"$regex": "jack"} }/pre
-- for this request server returns rows with names: "jack reacher", "blackjack", "michael jackson".

Note - regexp - is a powerfull thing and allow you to make advanced search. But there is other side of the coin - values for search - need to be escaped.

Return to “Issues”