0

Sometimes I need to run maintenance queries, like backfilling data of a new field I just created. How do I do this easily?

Firebase Functions seems targeted towards triggering on certain keywords or on certain schedules.

Basically, whatever I would do in MongoDB's terminal at will, I'd like to do in Firestore easily (even if I have to deploy code).

Jonatan Littke
  • 5,583
  • 3
  • 38
  • 40
  • You're definitely going to have to write code. Any reason why you can't go the easy route and run that code on your desktop? – Doug Stevenson Apr 02 '20 at 01:44
  • Oh, I'll definitely write code for it. But can you elaborate on the easy route on my desktop? Just write it... point my dev environment against production... execute it, and then throw it away? What about security rules, etc? – Jonatan Littke Apr 02 '20 at 01:51
  • That's an option to get you started. There's nothing stopping you, unless some firewall prevents it. – Doug Stevenson Apr 02 '20 at 01:52
  • What about Security Rules? To modify documents across multiple collections, I'll violate all of my rules. – Jonatan Littke Apr 02 '20 at 01:53
  • Code that uses server SDKs initialized with a service account bypass all Firebase security rules. – Doug Stevenson Apr 02 '20 at 01:54
  • Interesting. Don't know what that is yet but I'll look into it. Thanks. This sounds like the answer to me. – Jonatan Littke Apr 02 '20 at 01:55

1 Answers1

0

There is no set of "best practices" per se, but you can easily write programs to access Firebase and Google Cloud resources from your desktop. Just do some web searches for the server SDKs that provide access (there are many for different languages), and initialize them with a service account that has access to write data in the project.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • So the server SDK in this case seems to be the [Firebase Admin SDK](https://firebase.google.com/docs/admin/setup). However, answers [like these](https://stackoverflow.com/questions/44582508/firebase-admin-importing-it-to-react-application-throws-module-not-found-error) suggest it shouldn't be used in a local environment. The official docs even suggest not using it unless it's on a server. Would my local dev machine in this case really be considered 'server'? – Jonatan Littke Apr 02 '20 at 02:55
  • You can't use the Admin SDK or any of the server SDK in a web client environment. If you want to write JavaScript, it will be a node program that you run on the command line. – Doug Stevenson Apr 02 '20 at 03:01
  • [This video](https://www.youtube.com/watch?v=Z87OZtIYC_0&list=PLnepGR_yu2ekWVHK_PEXGBv3TxFDOrSLs&index=6&t=0s) outlined the concept neatly. Thanks for the pointers! – Jonatan Littke Apr 02 '20 at 03:43