one generated key for chained push

Viewed 82

Is there a way to let .push() || .push().key generate one key for chained .push()?

function saveItem(){
  const itemId = ref.push().key;
  let newItem = {id: itemId}

  ref.child(`items`)
      .push(newItem)
      .then(() => ref.child(`users/${uid}/items`)
      .push(itemId)
}

In example above I will generate 3 different keys instead of generating one even though there is itemId variable.

1 Answers
Related