How to query objects like javascripts includes?

How can I query the database using Moralis.Query to find objects where a column contains a certain string?

For Example

Object Name Anthony

I want to query all objects where the name includes “thony”. How would I do that?

You can do that with equalTo method.
In the below code ownerName is column name and Aegon is the string which you want to filter.

const query = new Moralis.Query("ClassName");
query.equalTo("ownerName", "Aegon");

Check more on query methods at : https://docs.moralis.io/moralis-dapp/database/queries#basic-queries

1 Like

Thats not like javascripts include, equalTo is equivalent of “===”. What I am looking for is equivalent for .includes() as I stated above. I want to get results if the value contains a substring.

Like if the value would be “apple” and I want to query that with "query.includes(“pple”).

ohh ok. Try it with .fullText method. This looks for that partial string to search

See the example in the below doc.
https://docs.moralis.io/moralis-dapp/database/queries#full-text-search

I tried that before but it is not giving me any results even tho when I filter inside the browser with string contains string, it gives results for my input values.

if (this.searchForWallet.length > 0) {
        console.log("searchForWallet", this.searchForWallet.toString())
        query.fullText("address", this.searchForWallet)
      }

image

There is a forum post where it says how to search with ignore case. It is a different method, I don’t remember it now.

the address field is always stored lowercase in my database and I am testing it with the value of “84” which isnt case sensitive since its a number tho

I just tried using “query.matches” and that seems to work. Not sure why matches works and then why there is a fullText. Seems to be solved for my case now but still needs clarification for why fullText doesnt work or what that is for then if we have matches

1 Like

It looks like .fullText is looking for word in a sentence/multiple words rather than part of the string.

Yea that ll probably be it. I checked the documentation again, “matches” is not mentioned in the docs, maybe you guys should add it. I only found matchesInQuery and matchesInKey which do different things