Logger not working & trying to pass 1 data on another array not working properly

Hi, the logger is not displaying anything, also I’m trying to pass 1 element from the results of the query and whenever I try to transfer 1 data to another array, it’s not transferring properly. What happened is that all the data is being passed.

I’m trying to transfer 1 data from the “results” to testResults.
Expected output
results = [{ “test”: “test”, “test2”, “test2”}]
testResults[0] = results[0];
testResult = {“test”: “test”}

What I got is
testResult = [{ “test”: “test”, “test2”, “test2”}]

Moralis.Cloud.define("getUserNFT", async (request) => {
	const query = new Moralis.Query("EthNFTOwners");
	query.equalTo("contract_type", "ERC721");
    if(request.user.get("accounts")){
    query.containedIn("owner_of", request.user.get("accounts"));
  	const queryResults = await query.find();
    const results = [];
  	for(let i = 0; i < queryResults.length; ++i){
    	results.push({
          	"tokenObjectId": queryResults[i].id,
        	"tokenId": queryResults[i].attributes.token_id,
        	"tokenAddress": queryResults[i].attributes.token_address,
        	"symbol": queryResults[i].attributes.symbol,
        	"tokenUri": queryResults[i].attributes.token_uri
        });
    }
    const testResults = [];
    testResults[0] = results[0];
    const logger = Moralis.Cloud.getLogger();
    logger.info(results); 
    logger.info("results",JSON.stringify(results))
    logger.info("results first element of array: ",JSON.stringify(results[0]))
  	return results;                    
    }
  	return;
});
1 Like

Hey @appsofdave

Logger shows you only string type info. It will not show you objects or arrays.

1 Like

I see, is there any other way to display the results that I got from the database? Because I’m trying to compare 2 data and it’s not detecting any data from the result.

For example on the result there’s tokenId.
I’m trying to compare results[0].tokenId to another result testResult[0].tokenId, but I can’t since it’s not detecting the data around it.

To see the data in logger you simply can stringiry your data using JSON.stringify() or .toString() and etc. Please share your server subdomain

Lemme try that, but for some reason my if conditions are not working properly because there’s no data whenever I try to compare the data from results… That’s my main issue.

2ag3bcl3ickr.bigmoralis.com

I’ve checked your logs and I see that error message:
Error: {"message":"Cannot read property 'get' of undefined","code":141} {"functionName":"getUserNFT","error":{"message":"Cannot read property 'get' of undefined","code":141},"params":{"user":"0x...07"}}

But your code has:

query.containedIn("owner_of", request.user.get("accounts"));

You can’t get anything from user object because you call this function without authorisation on the frontend.