[SOLVED] Can't access MongoDB data from cloud :(

Hey am trying to fetch the user from (_EthAddress class) using eth address, then using that result (user) am trying to check the email field in the _User class whether it is undefined or not. But the problem here is I could only use .find({useMasterKey:true}) which fetch all the data from a class and other fucntions like .equal etc aren’t working.

Please check my code below

Moralis.Cloud.define("exists", async (request) => {
        const query1 = new Moralis.Query("_EthAddress");
		const query2 = new Moralis.Query("_User");
		query1.equalTo("objectId", request.params.eth);
        const result = await query1.find({useMasterKey:true});
 		query2.equalTo("objectId", result.user);
		const result2 = await query2.find({useMasterKey:true});
		if (result2.email === undefined) {
			return true;
        else {
            return false;

The input will be eth address. The cloud code present in the documentation is not working for me. Looking for a quick fix so that I could proceed with my college project. Deadline is approaching :frowning:

you can use logger.info(JSON.stringify(variable_name)) in cloud code in order to debug

and to check that the parameters have the expected value

Moralis.Cloud.define("testFun", async (request) => {
  		const logger = Moralis.Cloud.getLogger();
  		const result1=await new Moralis.Query("_EthAddress")
		return result1;

Check the first log. Input is my eth address even though it is present in the DB the computed result is an empty array. what the heck should I do now ? :frowning: Dealing with this for the past two days.

You can check the case, if it is same case or if in is in lower case in the database

1 Like

Good catch man… U saved us :slight_smile: :+1:

1 Like