Search code examples
firebasefirebase-realtime-databasecommand-line-interfacestdinfirebase-console

Firebase CLI Avoid creating random object IDs STDIN


I am using Firebase CLI and trying to update a database with firebase:push. I would like to add an object to an existing database structure however it always creates a random object key that I do not want. Is it possible to omit this object key?

e.g.

I have used the following command in the CLI to add the json object.

> firebase database:push /users/cpaluk <<< '{"name":"cpaluk","key":"cpaluk","id":"test"}'

The object gets wrapped in an auto-generated random key KcqrF7JuJChspnOOo5h.

Firebase Database result

Thanks


Solution

  • When you call the Firebase CLI with firebase database:push it will always generate a push ID for the new data.

    If you want to specify the full path of the data yourself, use firebase database:set:

    firebase database:set /users/cpaluk <<< '{"name":"cpaluk","key":"cpaluk","id":"test"}'
    

    See the list of database commands in the Firebase documentation for the other commands that the CLI accepts.