[SOLVED] My cloud functions working on Moralis hosted server doesn't work anymore in my self hosted server

Hello,

Iā€™m working on migrating my formerly Moralis hosted server to a self hosted server. To do so, Iā€™m using the ā€œparse-server-migrationā€. Most of the migration work has been done but Iā€™m still struggling with some issues with cloud functions.

Long story short, I have a bunch of cloud functions that are working properly on Moralis server that Iā€™m trying to use in my self hosted one. For some reasons Iā€™m getting errors even tho the code is almost exaclty the same. Here is a simple example

Moralis server cloud function

/**
 * Return player's available prizes
 * @param playerId (objectId)
 */
Moralis.Cloud.define('getLoot', async (request) => {
  const playerId = request.params.id;

  const Prizes = Moralis.Object.extend('Prizes');
  const prizeQ = new Moralis.Query(Prizes);
  prizeQ.equalTo('ownerId', playerId);
  prizeQ.equalTo('status', 'locked');
  const results = await prizeQ.find();

  return results;
});

Self hosted cloud function

/**
 * Return player's available prizes
 * @param playerId (objectId)
 */
Parse.Cloud.define('getLoot', async (request: any) => {
  const playerId = request.params.id;

  const Prizes = Parse.Object.extend('Prizes');
  const prizeQ = new Parse.Query(Prizes);
  prizeQ.equalTo('ownerId', playerId);
  prizeQ.equalTo('status', 'locked');

  const results = await prizeQ.find();

  return results;
});

And I get this error :

error: TypeError: Cannot read property ā€˜protectedFieldsā€™ of undefined

Do you see anything wrong here ?

I donā€™t know exactly, maybe is related to the database, did you do a database load from the old database or you added new data on the self hosted server?

Yeah, Iā€™ve moved my moralis dB data to my own mongodb (just like in your tutorial https://youtu.be/l2qTyc-V9cM).
My dB is working fine, Authentication works (I get my data properly from dB to localstorage), and I got to test it add entries in my db just like in the video.

Maybe itā€™s related to some settings in the server migration repo?

you can try to add some debugging see from what line you get that error

This error can happen with data migrations using that tutorialā€™s script or MongoDB Compass - you can use mongodump / mongorestore to do a full migration.

1 Like
 const results = await prizeQ.find();

The error is coming from that line, thatā€™s all I know for now

Itā€™s working ! thank you for the help :pray:

1 Like