Get list of items from Firebase with their key

I sorted it out. Although I feel there’s a much cleaner and easier way of doing this.
I decided to write the data and get key property of push() and run an update() inserting the key as the taskid. That way when I get a list of tasks, I also get their key.

createTask(task: Task){
    let uid = task.uid;
    let key = this.ref.child(`/tasks/${uid}`).push(task).key;
    task.taskid = key;
    return this.ref.child(`/tasks/${uid}/${key}`)
    .update(task);
  }
1 Like