How can I retrieve data from collection and use them to redirect to another page?

Thanks in advance to anyone willing to help me. I’m a newbie with Velo.
I created a collection (“MemberInvitation”) where every item has three columns (named User, Name, and Event). Then, in the page I put a user input field (input1) and a button (button1): a user should insert its code (e.g. AN73UV) and clicking the button a new page should opens, simply adding /lunch or /dinner at the end of the wix page URL, as retrieved from the third column of the collection.


I tried with the following code but I cannot understand where I am wrong, since it does not work…

 import wixLocation from 'wix-location';
 import wixData from 'wix-data';
 export function button1_click(event) {
 		wixData.query('MemberInvitations')
 		.eq('User', $w('#input1').value)
 		.find()
 		.then(results => {
 				 let resultCount = results.totalCount;
 				 if (resultCount !== 0) {
 					 let firstItem = results.items[0];
  					 let event = firstItem.Event;
      					 wixLocation.to(`/${event}`);
      				}
      		});
      }

Anyone who can help me?

@fcristarella Inserting console.log statements in key places can help you determine what is really happening with it. The query code looks fine, but I would put the following line right below the .then statement and then examine the object returned in the developer console at the bottom when you preview.

console.log(results);

You may need to trim trailing spaces from the Event field like the following. Otherwise, the event variable could be something like "lunch ". Velo will not be able to find a page by that name.

let event = firstItem.Event.trim();

Thank you, I solved. In the console log it said " WDE0025: The MemberInvitations collection does not exist. You cannot work with a collection using the Data API before it is created in the Editor. ".
It seems that there was a missing element in the query. It should have been:

wixData.query('Marketing/MemberInvitations')

Now it works fine.