Query All Columns of a Class? (query.fullText)

Is this possible? I don’t think querying all columns has been asked here… and I don’t see how after reading Moralis and MongoDB docs.

Okay as an alternative I made a cloud function querying the 5 relevant keys using the .or function but I’m getting a 500 error every time… Is there something wrong with my code?

Moralis.Cloud.define("searchProducts", async (request) => {
  const queryBrand = new Moralis.Query("Products");
  queryBrand.fullText("brand",request.params.searchInput);
  
  const queryTitle = new Moralis.Query("Products");
  queryTitle.fullText("title",request.params.searchInput);
  
  const queryDescription = new Moralis.Query("Products");
  queryDescription.fullText("description",request.params.searchInput);
  
  const queryModel = new Moralis.Query("Products");
  queryModel.fullText("model",request.params.searchInput);
  
 
  const mainQuery = Moralis.Query.or(queryBrand, queryTitle, queryDescription, queryModel);
  
  const results = await mainQuery.find() 
 
  return results;
});

Any specific error message in dashboard?

This is what I’m getting

Hold on I forgot what dashboard is … says text index required

It sounds like it wants an index of that type. You can connect directly to mongodb and add an index (not super easy to do)

I saw someone else here run into the same problem and Ivan recommended them switch to .matches, I’m able to console log it so it’s working adding it under useEffect causes too many fetches tho…

I remember now of matches:

it also seems to work with case insensitive

1 Like

I just run into a similar issue where Moralis.Query.or didn’t work so I used .find() on each query then combined the arrays.

Moralis.Cloud.define("searchProducts", async (request) => {
  const queryBrand = new Moralis.Query("Products");
  queryBrand.fullText("brand",request.params.searchInput);
  const queryBrandResults = await queryBrand.find();
  
  const queryTitle = new Moralis.Query("Products");
  queryTitle.fullText("title",request.params.searchInput);
  const queryTitleResults = await queryTitle.find();
  
  const queryDescription = new Moralis.Query("Products");
  queryDescription.fullText("description",request.params.searchInput);
  const queryDescriptionResults = await queryDescription.find();

  const results = await [...queryBrandResults, ...queryTitleResults, ...queryDescriptionResults];

  return results;
});