Data Query works for only some Fields

Hi -

I am working on a data query on a dynamic item page and I am trying to access another dataset. The dynamic item page is linked directly to the Members dataset, and I am accessing data from a Earnings dataset. So, I do the following:

wixData.query("Earnings") 
	.eq("fullName", "James Lowell") 
	.find() 
	.then( (results) => { 
		items = results.items; 
		$w("#text18").text = items[0].initialInvestment.toString(); 
		$w("#text19").text = items[0].currentValue.toString(); 
		$w("#text20").text = items[0].profitDollars.toString(); 
		$w("#text21").text = items[0].profitPercent.toString(); 
	}) 
	.catch( (error) => { 
		$w("#text18").text = "Error"; 
		$w("#text19").text = "Error"; 
		$w("#text20").text = "Error"; 
		$w("#text21").text = "Error"; 
    	errorMsg = error.message; 
    	code = error.code; 
} ); 

This is a query that posts results to texts boxes. This query works actually, so there is nothing wrong with this code.

HOWEVER:
When I try to switch the equality parameter to “.eq(“email”, “jalowell”)”, which is another field in the Earnings dataset and “jalowell” is a valid entry, the query does not work. I hope there is an easy fix to this, as it doesn’t seem like it should be terribly hard. Please let me know! Thank you!!

So, as an update, “email” is a reference ID - I think this has some importance but don’t know where to go from here. Thank you.

Hey,
Currently in order to query a referenced field you’d need to find the _id of the referenced value in the other collection and use that.
Meaning, before the code you added, you should add:

wixData.query("ReferencedCollection")
		.eq("email", "jalowell")
		.find()
		.then( (results) => {
			let emailId = results.items[0]._id;

and then change your inner query to “.eq(“email”, emailId)”.