Why does the api not match the exact data

I create a function to get data through api. Everything works fine in the testing console, but the matching mechanism doesn’t seem to work when I’m actually fetching the data using api, and I end up with all of the data. My codes of function are as follows:

exports = async function(searchTerm, contentLengthLimit = 100000) {
  const collection = context.services.get("MyCluster").db("mydatabase").collection("mycollection");

  const lowerCaseSearchTerm = searchTerm.toString().toLowerCase();

  const query = { "name": { "$regex": lowerCaseSearchTerm } };

  const result = await collection.find(query).toArray();
  if (result && result.content && result.content.length > contentLengthLimit) {
    result.content = result.content.substring(0, contentLengthLimit);
  }

  return result;
};