Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Query service with Request that gets information based on part of the data field

Hi

I have a query service. Return values from the db that contain an exact match works fine. However how do I use the Contains argument to retrieve any data that contains any part of the searched for data?

return('contains({"Client": "' + (value) + '"})');

Does not work. Not sure if is a syntax issue or if this method cannot be used.

Thank you.

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Query service with Request that gets information based on part of the data field

Thanks, but I am battling with the syntax.....

I want the same result as this
return('{"Client": "' + value + '"}');
but return any part and any case

I have tried various things ie.

return('{"Client":{"$regex": "' + value + '", "$option": "i"}}');
but cant get it to work

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

Query service with Request that gets information based on part of the data field

Try this variant:
return('{"Client":{$regex: "' + value + '"}}');

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Query service with Request that gets information based on part of the data field

Does work but is case sensitive.

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

Query service with Request that gets information based on part of the data field

Please take a look at screenshot,
Image

code from where clause:
pre{'Name':{$regex:"test"}}/pre

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Query service with Request that gets information based on part of the data field

return('{"Client":{$regex: "value"}}'); does not work at all

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Query service with Request that gets information based on part of the data field

value = variable that could be anything

This works
return('{"Client":{$regex: "'+ value +'"}}');
but but you have to type the exact case

For cas insensitive I tried this but it does not work
return('{"Client":{$regex: "'+ value +'", "$option": "i"}}');

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Query service with Request that gets information based on part of the data field

This works.....

return('{"Client":{$regex: "'+ value +'"}}'); but is is case dependent.

now to remove case sensitivity I do this as suggested in other posts
return('{"Client":{$regex: "'+ value +'", "$option": "i"}}');
It does not work. It is still case dependent.

With reference to your post...
http://docs.mongodb.org/manual/refere...
syntax for $option is $options???? Which is the correct syntax

This is very confusing, there is no consistency in syntax. I never know when to use " or '. It seems there are many variations of the same thing and it is a hit and miss.

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

Query service with Request that gets information based on part of the data field

Hi Deon,

Please try this:
pre
{"Client":{$regex: "'+ value +'", $options: 'i'}
/pre

Return to “Issues”