Skip to content Skip to sidebar Skip to footer

Firebase POST Custom ID

is there a way to set a custom ID in Firebase when using the POST method? something like: { 'users': { 'user_one': { 'username': 'jdoe', 'password': '123' }

Solution 1:

Make sure to use the put instead of the post request else you'll end up with the auto generated id inside of your "user_one"

POST will give you:

{
  "users": {
    "user_one": {
      "134134hnj34nuj134bn": {
        "username": "jdoe",
        "password": "123"
      }
    }
  }
}

axios.put('https://projectname.firebaseio.com/padres/user_one.json', padre)

PUT will give you what you want.

{
  "users": {
    "user_one": {
      "username": "jdoe",
      "password": "123"
    }
  }
}

Solution 2:

There sure is. Just use the HTTP PUT method and specify the entire path. Depending on your library it may be as simple as:

axios.post('https://projectname.firebaseio.com/padres/user_one.json', padre)

For more, see the Firebase REST API documentation on the PUT command.


Solution 3:

If you are using Php cURL, i had achieved this with PUT by adding my custom ID in url.


Post a Comment for "Firebase POST Custom ID"