Get specific data from query

the result includes everything from the TRIPOLI database how do i get specific fields as results.
In the query result i just want to get the tittle of the query (its a field in my database).

export function container1_click(event) {
	const user = wixUsers.currentUser; 
	const userId = user.id; 
	const itemId = event.context.itemId; // this is the item in the repeater assuming that the button is in the repeater.
	wixData.query("TRIPOLI") // get the item from the database collection.
	.eq("_id", itemId)
	.find()
	.then((results) => {
		const saveit = results.items[0];
		saveit.userId = userId; // adding a field of the current user to the database in order to distinguish between other users wishlist. 
		let toSave = {
					"title": saveit,
					"userId": userId
				};
				wixData.save("Saveditem", toSave);
			console.log(saveit);
	
});
}

Hi Amit,

From your result, just access the field from the desired row in your results:

const saveit = results.items[0];
let title = saveit.title;

I hope this helps.

Yisrael

thanks it worked.

Hello,
Can you please tell me what’s wrong in my code below. I have all time zero in $w(‘#input3’).value despite the fact that the record exists in the database. Thank you in advance.

export function startBtn_click(event) {
//Get current user email
getUserEmail();
//Check if the user already has a profile in the profiles database
searchForDuplicates();
}
export function getUserEmail() {
$w(‘#input1’).value = “”;
let currentUser = wixUsers.currentUser;
return currentUser.getEmail()
.then( (userEmail) => {
$w(‘#input1’).value = userEmail;
} )
. catch ((err) => {
return err;
} );
}

export function searchForDuplicates() {
wixData.query(“myCollection”)
.eq(“LoginMail”, $w(‘#input1’).value)
.find()
.then( (results) => {
$w(‘#input3’).value = results.length;
if (results.length >= 1)
{
$w(‘#input2’).value = “found”;
}
else
{
$w(‘#input2’).value = “not-found”;
}
})

. **catch** ( (error) => { 

let errorMsg = error.message;
let code = error.code;
} );
}

You need to make sure that you use the Field Key and not the Field name of a collection. The Field Key always starts with a small letter:


Instead of:
.eq(“LoginMail”, $w(’ #input1 ').value)
You probably want:
.eq(“loginMail”, $w(’ #input1 ').value)

Good luck,

Yisrael

Hey Yisrael Thank you!

I wish I had discovered your answer hours ago. I was trying to JSON.parse the return from my query … and getting nowhere.

It would be good to see a short article about this in the docs. But glad you’re here.

wixData . query ( “Collectionname” )
//.eq(“emailid”, email1)
. find ()
. then (( results ) => {

        **let**  saveit  =  results . items ; 

I need to get particular filed value from all rows? Please share your solutions. Thank you