Hi guys,
I'm running into an issue querying the built-in "Bookings/Staff" database. I am trying to only pull back one record that matches the name "Rob". However even though I am using the contains filter I'm getting all staff members back.
Here is my code snippet:
//value of getname = 'Rob'
function getServiceData(getname) { console.info('Looking up: ' + name); wixData.query("Bookings/Staff") .contains('name', getname) .find() .then( (results) => { StaffData = results.items console.info(results.items) } ); }
When this code runs I get all 3 staff members back, David, Rob and Matteo. What am I doing wrong here?
Please post the editor URL of your site. Only authorized Wix personnel can get access to your site in the editor. Please include the name of the page involved.
Yes, simply because you are not telling the code what name the query should contain.
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#contains
Or you will have to add into your code the value of getname before the query runs itself so that it knows what the getName value it is supposed to be looking for in the contain query.
import wixData from 'wix-data'; // ... wixData.query("myCollection") .contains("description", "some words")