How do make specific queries for columns in my class?

How do make specific queries for columns in my class?

For example, I have a Metadata class and inside that class are columns: ethAddress, background, and character.

What Iโ€™m trying to do is when the user presses the Activate button it calls onActivateBackground(), which gathers the new metadata and suppose to update the data in Background column in the backend for that user.

The code snippet is below:

    // function to change Background
    const onActivateBackground = async ({ type, name, thumbnail, link }) => {
    let ethAddress = user.get("ethAddress");

    // check to see if there is an instance in Metadata class for ethAddress
    const Metadata = Moralis.Object.extend("Metadata");
    const query = new Moralis.Query(Metadata);
    query.equalTo("ethAddress", ethAddress);
    query.select("Background");
    const results = await query.first();

    // get all data from local and update data on backend
    results.set("type", type);
    results.set("name", name);
    results.set("thumbnail", thumbnail);
    results.set("link", link);
    await results.save();
  };

Why doesnโ€™t this work? The data is not updating on the backend. Any help would be appreciated!

you can use logger.info(JSON.stringify(variable_name)) for logging

then you can start with simpler queries until you make them work

I figured it out! Instead of using the query.select("Background"); line of code in the query, I used the object path in the set parameter instead and it worked! Here is the new chuck of code. Cheers!

    let ethAddress = user.get("ethAddress");

    // Need to reference instance in backend
    const Metadata = Moralis.Object.extend("Metadata");
    const query = new Moralis.Query(Metadata);
    query.equalTo("ethAddress", ethAddress);
    const results = await query.first();

    // update that data
    results.set("Background.type", type);
    results.set("Background.name", name);
    results.set("Background.thumbnail", thumbnail);
    results.set("Background.link", link);
    await results.save();
  };