[SOLVED] Moralis.Object.extend error when update from V1 to V2

Hi Moraliser,
I have some code for get list Transaction collection from my frontend. Working last V1 but got error V2.
What can I do in this case? Document for V1 is full but Doc for V2 not good :frowning:

const Transactions = Moralis.Object.extend('Transactions');
    const query = new Moralis.Query(Transactions);
    query.equalTo('user_id', Moralis.User.current().id);
    query.equalTo('type', 1);
    query.descending('createdDate').skip(offset).limit(limit);

    const results = await query.find({useMasterKey: true});
    setTransactions(results);
error: TypeError: Cannot read properties of undefined (reading 'protectedFields') {"code":1,"stack":"Error: TypeError: Cannot read properties of undefined (reading 'protectedFields')\n  

what line gives that error?

this one:

this is front end or backend?

where from you get this user id?

in Fronrend, Nextjs

const results = await query.find();

error on Parse self-host server

useMasterKey will not work in front end

you can try to call a cloud function that makes that query in the database

does this table named Transactions exist in the database?

Ok bro,
If update to V2, we must call cloud functions for all.

Transactions exits in DB. Still working if I using V1.
image

I donโ€™t know exactly what is the issue here, you can try to add more logging to see if everything looks as expected for the parameters, you can try it from cloud code to see if it works

it looks like others had a similar error with parse server:

OK I will try with cloud code first.

Hi cryptokid,

I tried with cloud functions and got same error. I though cloud functions not cause in this case;

What is โ€˜protectedFieldsโ€™

 TypeError: Cannot read properties of undefined (reading 'protectedFields')

you can try to read more here

it works with other tables?

is the user authenticated or now when you try that?

if I change to tables User is OK. Tables User automatically created.
I create manually table Transactions by MongoDB Compass

I created Transaction from client tool MongoDB Compass.
How to sync or tell Moralis I created new tables ?

you can try to install parse dashboard for parse server, a similar interface with the database dashboard that you see for moralis server and try to create the table from there

you can also create the table directly from code, similar to how you make the query

I install Prase Dashboard and worked.
thank you :slight_smile:

1 Like

I was also facing this issue for the past 2 days. There is no resource about this in the Moralis Documentation.
A suggestion- Please provide proper steps and things to keep in mind to migrate Cloud Code to a Self-Hosted Moralis server. Also, earlier cloud code was written in JavaScript, but now your tutorials require us to convert all the cloud code from JavaScript to TypeScript. Please make a tutorial to create a self-hosted moralis server using javascript