Start a new topic
Answered

Add a string parameter and get all data that contains any from this string

I have an API that gets a data from a collection. What I want to do is pass a string parameter and get all data that contains this string.

 

For Example:

When hitting this API URL:

 

https://baas.kinvey.com/appdata/XXXXX/WorldCities?query={"name":"am"}

 

Will get all results that the field name has "am" characters, Ie: "America","Amsterdam",...etc



Best Answer

Hi Mohamed,


You may use a $regex query for that. 


There is a limitation to anchor all query conditions (they must start with ^). So to execute a 'contains' query, you may use the following:

?query={"name":{"$regex":"^.*yourString.*"}}


Please note that there is also a limitation that the regext cannot be case-insensitive.


Regards

Martin


Answer

Hi Mohamed,


You may use a $regex query for that. 


There is a limitation to anchor all query conditions (they must start with ^). So to execute a 'contains' query, you may use the following:

?query={"name":{"$regex":"^.*yourString.*"}}


Please note that there is also a limitation that the regext cannot be case-insensitive.


Regards

Martin


1 person likes this

That's it. Thanks so much dear Martinn.


Would you please share with me where is it on the documentation as It does not exist here


https://devcenter.kinvey.com/rest/guides/getting-started


and sorry another question, is it a javascript regex?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions


Thanks so much



Login or Signup to post a comment