Get Ref Key after push?

Hey Guys,

First of all thanks for your work on this!

The firebase web documentation here: https://firebase.google.com/docs/database/web/read-and-write describes the ability to get a key from a newly pushed ref like this

  // Get a key for a new Post.
  var newPostKey = firebase.database().ref().child('posts').push().key;

This doesn’t seem to work using this, as push() seems to return a promise. Also from what I can tell, the source code has a return type of void. Is there a way to do this?

Author: Fantashit

2 thoughts on “Get Ref Key after push?

  1. const postKey = firebase.database().ref().child('posts').push().key; works for me with "react-native-firebase": "^1.0.10",

  2. use this:

    var TheUniqueKeyOfPush = firebase.database().ref().push().getKey();

    and then:

    Use the variable because it contains the unique key.

Comments are closed.

Get Ref Key after push?

Hey Guys,

First of all thanks for your work on this!

The firebase web documentation here: https://firebase.google.com/docs/database/web/read-and-write describes the ability to get a key from a newly pushed ref like this

  // Get a key for a new Post.
  var newPostKey = firebase.database().ref().child('posts').push().key;

This doesn’t seem to work using this, as push() seems to return a promise. Also from what I can tell, the source code has a return type of void. Is there a way to do this?

Author: Fantashit

4 thoughts on “Get Ref Key after push?

  1. const postKey = firebase.database().ref().child('posts').push().key; works for me with "react-native-firebase": "^1.0.10",

  2. use this:

    var TheUniqueKeyOfPush = firebase.database().ref().push().getKey();

    and then:

    Use the variable because it contains the unique key.

Comments are closed.

Get Ref Key after push?

Hey Guys,

First of all thanks for your work on this!

The firebase web documentation here: https://firebase.google.com/docs/database/web/read-and-write describes the ability to get a key from a newly pushed ref like this

  // Get a key for a new Post.
  var newPostKey = firebase.database().ref().child('posts').push().key;

This doesn’t seem to work using this, as push() seems to return a promise. Also from what I can tell, the source code has a return type of void. Is there a way to do this?

Author: Fantashit

2 thoughts on “Get Ref Key after push?

  1. const postKey = firebase.database().ref().child('posts').push().key; works for me with "react-native-firebase": "^1.0.10",

  2. use this:

    var TheUniqueKeyOfPush = firebase.database().ref().push().getKey();

    and then:

    Use the variable because it contains the unique key.

Comments are closed.