Sains
Sains

Reputation: 477

Can we insert a data into Firebase realtime Database?

One child node of my Firebase realtime database has become huge (aroung 20 GB) and I need to purge this and insert the the extracted data of last month from the backup into the Firebase realtime database using Python Admin SDK.

In the documentation, I see the following options:

set - Write or replace data to a defined path, like messages/users/

update - Update some of the keys for a defined path without replacing all of the data

push - Add to a list of data in the database. Every time you push a new node onto a list, your database generates a unique key, like messages/users//

transaction - Use transactions when working with complex data that could be corrupted by concurrent updates

However, I want to add/insert the data from the firebase backup. I have to insert because the app is used in production and I cannot afford the overwrite of data.

Is there any method available to insert/add the data and not overwrite the data?

Any help/support is greatly appreciated.

Upvotes: 1

Views: 923

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

There is no way to do this in Firebase Realtime Database without reading the current value of each location.

The only operation that allows you to update data based on its existing value is a transaction. A Firebase transaction gives you the (likely) current value at a location, and you then return what the new value should become.

But if the data you're restoring is (largely) the same as the data you have in the database, you might be able to use an update() call with sufficiently deep paths.

Upvotes: 1

Related Questions