Search code examples
mongodbhttpparse-server

Is there a way to save ParseObject without make a HTTP request to the REST API?


I didn't find very much about this topic, so I wonder if it is an easy task to achieve or if it's actually not possible. My problem is that I have a lot of HTTP requests on my server even if a Cloud function is called only once. So I suppose that all the object updating / savings / queries are made by using the REST API. I have so many HTTP requests that several hundred are going timeout, I suppose for the huge traffic that it's generated.

Is there a way to save a ParseObject by executing the query directly to MongoDB? If it's not possible at the moment can you give me some hints if there are already some helper functions to convert a ParseQuery and a ParseObject to the relative in MongoDB so that I can use the MongoDB driver directly?

It's really important for my application to reduce HTTP requests traffic at the moment.

Any idea? Thanks!

EDIT: Here an example to reproduce the concept:

Make a cloud function:

Parse.Cloud.define('hello', async (req, res) => {
  let testClassObject = new Parse.Object('TestClass');

  await testClassObject.save(null, {useMasterKey: true});

  let query = new Parse.Query('TestClass');

  let testClassRecords = await query.find({useMasterKey: true});

  return testClassRecords;
});

Make a POST request: POST http://localhost:1337/parse/functions/hello

Capture HTTP traffic on port 1337 using Wireshark: enter image description here

You can see that for 1 POST request other 2 are made because of the saving / query code. My goal would be to avoid these two HTTP calls and instead make a DB call directly so that less traffic will go through the whole webserver stack.

Link to the Github question: https://github.com/parse-community/parse-server/issues/6549


Solution

  • The Parse Server directAccess option should do the magic for you. Please make sure you are initializing Parse Server like this:

    const api = new ParseServer({
      ...
      directAccess: true
    });
    ...