[SOLVED] Query - string search toLowercase

I’m doing a string query and want to match results regardless of how letters are formatted (lowercase, uppercase, capitalized).

Is there any way I can convert the database results to lowercase?

I’m converting the initial search term to lowercase first.

const searchTerm = s?.toString()?.toLowerCase();

const Profiles = Moralis.Object.extend('Profiles');
const query = new Moralis.Query(Profiles);

query.select('name', 'logo', 'ethAddress');
query.startsWith('name', searchTerm);
query.limit(5);
const results = await query.find();

return res.status(200).json(results);

Example: a name in the database could be ABC. I’d like to find all results whether it’s spelled ‘abc’, ‘ABC’, ‘AbC’, ‘Abc’, etc.

ahh, it looks like .fullText() works and ignores the casing.

const searchTerm = s?.toString()?.toLowerCase();

const Profiles = Moralis.Object.extend('Profiles');
const query = new Moralis.Query(Profiles);

query.select('name', 'logo', 'ethAddress');
query.fullText('name', searchTerm);
query.limit(5);
const results = await query.find();

return res.status(200).json({ results });

Not sure if there is also another way which is less resource-intensive then full text search.

1 Like