Search code examples
firebase-realtime-databasefirebase-cli

Why firebase CLI push data to a random path on real-time database?


Why when I run this command on firebase CLI

firebase database:push /messages --data '{"users_test":"id","test","token"}'

I want the data to insert to /data/messages/ in a real-time database

messages
   test: "token"
   users_test: "id"

But it always inserts to /data/messages/-MbJqEUNN6EhisiyvbV8

messages
 -MbJqEUNN6EhisiyvbV8
   test: "token"
   users_test: "id"

Why the random string is generated there


Solution

  • That's literally what database:push does: it generates a unique ID under the location, and adds the data there.

    If you want to write directly to the location, user database:set. That replaces any existing data at messages with the data you specify in the command.