Page 1 of 3
Query service with Request that gets information based on part of the data field
Posted: Sun Nov 24, 2013 3:16 pm
by Deon
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.
Query service with Request that gets information based on part of the data field
Posted: Sun Nov 24, 2013 3:50 pm
by Igor
Query service with Request that gets information based on part of the data field
Posted: Sun Nov 24, 2013 7:35 pm
by Deon
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
Query service with Request that gets information based on part of the data field
Posted: Sun Nov 24, 2013 7:40 pm
by Igor
Try this variant:
return('{"Client":{$regex: "' + value + '"}}');
Query service with Request that gets information based on part of the data field
Posted: Sun Nov 24, 2013 8:04 pm
by Deon
Does work but is case sensitive.
Query service with Request that gets information based on part of the data field
Posted: Sun Nov 24, 2013 11:27 pm
by Igor
Please take a look at screenshot,
code from where clause:
pre{'Name':{$regex:"test"}}/pre
Query service with Request that gets information based on part of the data field
Posted: Mon Nov 25, 2013 3:38 am
by Deon
return('{"Client":{$regex: "value"}}'); does not work at all
Query service with Request that gets information based on part of the data field
Posted: Mon Nov 25, 2013 3:53 am
by Deon
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"}}');
Query service with Request that gets information based on part of the data field
Posted: Mon Nov 25, 2013 4:11 am
by Deon
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.
Query service with Request that gets information based on part of the data field
Posted: Mon Nov 25, 2013 5:43 am
by Illya Stepanov
Hi Deon,
Please try this:
pre
{"Client":{$regex: "'+ value +'", $options: 'i'}
/pre