Return the data from beforeFind trigger and stop the Find query


I am integrating ElasticSearch to Parse Server for caching and searching capabilities.

I’ll cache data of few specific classes into the ElasticSearch. When a find query is executed on one of those classes then a check is first made to see if the data is cached on the Elastic server. If it is then return it. If not, get it from the parse database.

I want to complete this process by using the beforeFind trigger of a class to check in the ElasticSearch.

For example in Vendor class,

// main.js
const es = require("./elasticsearch.js");
Parse.Cloud.beforeFind(Parse.Vendor, async (request) => {
  // Call Elastic function
  es.esSearch(request, (res) => {
    // if response has data then stops the find query return the data
    // If not, continue to find query

// elasticsearch.js
exports.esSearch = async function (req) {
   // returns data

So, How to return data from the beforeFind trigger without throwing error and also stop executing of find query?

Similar to this feature


I believe there is no way to do that using the beforeFind trigger. I’d try to do that using cloud code functions.