Start a new topic
Answered

query "starts with" or "like" type

 Hi! For example I have the names "Alan" and "Alen" in my collection. There is a query for the case where I search all the names starting with "al" ??


Best Answer

Hello Megahard Technologies,


In addition to Martin's earlier comment, I would like to tell you that we ONLY support (or recommend) regex for querying only to the beginning of a string and it should be case sensitive. We have placed restrictions on regex queries because they are very computationally expensive given our current platform setup. We do not recommend the full-text regular expression searches as they are very computationally expensive. We only support regex where strings start with the regex. 



Thanks,

Pranav

Kinvey


Hi Dan,


Doing this via the API console is pretty simple you can simply request: /appdata/kid_Te5Spq4_zC/firstNames/?query={"firstName":{"$regex":"^Jo"} }


Which would match "Joe" or "John" but not "john" or "joe" (it's case sensitive / anchored to the beginning of the string).


Doing this in one of the javascript libraries means that you could use the "contains" query:  which is outlined over here:  http://devcenter.kinvey.com/html5/guides/datastore#operators


Please let me know if you need anymore help with this.


Thanks,


1 person likes this

 Damien Bell in the link you provided i didnt find any such examples. can you give some more insight to this. do i need to write $regx is it mandatory.

Hi,

The REST API request is indeed /appdata/KID-HERE/COLLECTION-NAME/?query={"firstName":{"$regex":"^Jo"} }.


If you are using the Kinvey JavaScript SDK, you would use matches operator like this:


      const collection = "Authors";
      const field = "firstName";
      const regex = "^Jo";

      const query = new Kinvey.Query();
      query.matches(field, regex);

      const bookStore = Kinvey.DataStore.collection(collection, Kinvey.DataStoreType.Network);
      bookStore.find(query)
      .subscribe(function onNext(data) {
        console.log(data);
      }, function onError(error) {
        console.log("err", err);
      }, function onCompleted() {
        console.log("done");
      });


Let me know if this has helped.


Martin Apostolov

Kinvey Support

Answer

Hello Megahard Technologies,


In addition to Martin's earlier comment, I would like to tell you that we ONLY support (or recommend) regex for querying only to the beginning of a string and it should be case sensitive. We have placed restrictions on regex queries because they are very computationally expensive given our current platform setup. We do not recommend the full-text regular expression searches as they are very computationally expensive. We only support regex where strings start with the regex. 



Thanks,

Pranav

Kinvey

Login or Signup to post a comment