Get index of item in dataset

Thanks @amandam ; to bring closure on this thread.

I could not find a shortcut way of doing it (eg. getIndexById() ); so I did it programmatically directly on the database.

My code is here for everyone to see for future reference. I resorted to running a back-end code routinely which would sort the database, iterate through it, and update everyone’s position based on the sorted criteria. It did the trick and will work for small waitlists.

export function sortWaitlist ( ) {

wixData . query ( "Waitlist" ) 
  . ascending ( "totalSum" ) 
  . descending ( "totalReferrals" ) 
  . ascending ( "_createdDate" ) 
  . eq ( 'type' ,  'Waitlist' ) 
  . find () 
  . then ( ( results ) => { 

  **let**  count  =  results . totalCount ; 
  **let**  items  =  results . items ; 

  **for** ( **var**  i  =  0 ;  i  <  count ;  i ++){ 

    **let**  toUpdate  = { 
      '_id' :  items [ i ]. idUpdate , 
      'email' :  items [ i ]. email , 
      'firstName' :  items [ i ]. firstName , 
      'lastName' :  items [ i ]. lastName , 
      'position' :  i  + + 1 , 
      'referralCode' :  items [ i ]. referralCode , 
      'referral' :  items [ i ]. referral , 
      'type' :  'Waitlist' , 
      'totalReferrals' :  items [ i ]. totalReferrals , 
      'totalSum' :  items [ i ]. totalSum , 
    } 

    wixData.update("Waitlist",toUpdate); 

    } 

})  // End getItems 

} // End For Loop