Firetool

Home / Docs / Saved changes and scripts

Docs

Save a Firestore field change, run it again, or export it as a script

Keep a bulk field change with its query, run it on staging first and production next with the same preview and checks, or turn it into a Node.js script that uses the Firebase Admin SDK. Running a change in Firetool needs Pro, like any bulk change.

Save a change

  1. Open the collection, add the filters for the documents you want, and choose Run.
  2. Open Set a value in documents…, Rename field in documents… or Delete field from documents… from a column header's ⋮ menu (Set a value is also in Actions ▾), and fill it in: the field, the change and the value.
  3. Choose Save…, give it a name, and choose Save. The change is kept with the query of your last Run. You can still preview and apply it now, or close the dialog.

Every kind of field change can be saved: set a value, add a number, convert a type, a new random ID, find and replace, rename and delete.

Your saved changes

Open Tools → Tasks and choose Saved. Each saved change shows what it does, the collection and filters it applies to, and its last runs, with the project and how many documents changed. ✎ renames it and ✕ deletes it; deleting a saved change doesn't change any data.

Run it again

  1. Choose Run….
  2. Choose the Project and type the Database and Collection. They start as the ones it was saved in; pick your staging project first, for example, then production.
  3. Choose Open and preview. Firetool opens a tab with the saved query in that project and the same dialog, already filled in.
  4. Choose Preview to see how many documents will change, with examples, then Apply.

A run is a normal bulk change: a large one shows the estimated cost first, a production project asks for its project ID, a read-only one is refused, documents changed after the preview are skipped, and every write is in the audit log. Values such as document references are made for the project you run it on.

Export as a script

  1. Choose Script, pick the project, database and collection, and choose Show the script.
  2. Choose Copy, or Save as a file… to save it as a .js file.
  3. On a computer with Node.js 18 or later, in the file's folder, run npm install firebase-admin.
  4. Run node your-file.js. It signs in with Application Default Credentials (gcloud auth application-default login, or GOOGLE_APPLICATION_CREDENTIALS pointing at a service account key) and lists what would change, without writing anything.
  5. Run node your-file.js --apply to make the changes. A document changed after the script read it is skipped.

A script runs outside Firetool, so its changes don't go through Firetool's checks (roles, read-only and production rules) and aren't in Firetool's audit log. Use Run… when you want those.

Questions

Where are saved changes kept?

On this computer, with your other Firetool settings. They aren't sent anywhere.

Can I save a change made on selected rows only?

A saved change keeps the query of your last Run, so running it again applies to every document that query matches. Add filters to the query to narrow it.

Does the script need Firetool installed?

No. It only needs Node.js and the firebase-admin package, and an account that can write to the project.