Skip to content

Instantly share code, notes, and snippets.

@manniru
Created September 27, 2023 10:04
Show Gist options
  • Save manniru/526d81f696c73cf4fa9f950b41cfbcc1 to your computer and use it in GitHub Desktop.
Save manniru/526d81f696c73cf4fa9f950b41cfbcc1 to your computer and use it in GitHub Desktop.
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
# 1. Initialize Firebase Admin SDK
cred = credentials.Certificate('./e-naira-firebase-adminsdk.json')
firebase_admin.initialize_app(cred)
db = firestore.client()
# 2. Read all the documents from the original collection
old_collection = db.collection('_offline_transactions')
documents = old_collection.stream()
for doc in documents:
# 3. Write each of those documents to the new collection
new_doc_ref = db.collection('_offline_transactions1').document(doc.id)
new_doc_ref.set(doc.to_dict())
# 4. Delete the document from the old collection
doc.reference.delete()
print("Collection renamed successfully!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment