I have a database with user ID (._id), user names, and some statistics.
I have a drop-down, which is tied to the database list of user names.
When selecting a user-name, I want to display some of the statistics for that user on the page.
The only way I’ve found to do this, is to take the ‘.value’ of the drop down (user name), and then query the database for names, to pull the ID.
This works, but takes a few seconds to refresh the data each time.
I’m sure there’s a faster way to directly know the id from the drop-down selection, since it’s all tied to the database already anyways. I can’t see a way to make “Labels: name, Value: ID”. What am I missing?
Thanks for the help, appreciate the suggestions.
For reference, what I’m doing now is something like this:
export function userDropDown_Change(event) {
wixData.query( "MyDatabase" )
.eq( "name" , $w( '#userDropDown' ).value )
.find()
.then( results => {
**var** userData = results.items[ 0 ].data;
display_data_function( userData);
}
}
Perhaps this way? This way, you do not need to query all the time.
You query just ONCE (normaly this should be faster).
import wixData from'wix-data';
var myDatabase = "HereTheNameOfYourDB"
var REFERENCE = "name"
var VALUE = $w('#userDropDown').value
$w.onReady(()=>{
let QUERY = wixData.query("MyDatabase")
$w('#userDropDown').onChange(()=>{
QUERY.eq(REFERENCE, VALUE).find()
.then((results) => {
if(results.items.length > 0){
let firstItem = results.items[0]
let items = results.items
let userData = results.items[0].data
console.log(firstItem)
console.log(items)
console.log(userData)
display_data_function(userData)
}
else{ }
})
.catch((err) => {
let errorMsg = err;
});
})
})
You can also use LIMITATION…(if you do not need to load the whole DB).
let QUERY = wixData.query("MyDatabase").limit(100)
I don’t see a significant change in performance with this.
This is still running a user-name search every time a change is made, which I’m sure is where the slow down is.
Hopefully I got the performance hooks setup correctly, but the run-times I’m seeing are:
wixData.query(): <5ms
query.find(): 2,000ms+