How to import CSV or JSON to firebase cloud firestore

前端 未结 11 1048
星月不相逢
星月不相逢 2020-11-29 16:19

Is there a way to import CSV or JSON to firebase cloud firestore like in firebase realtime database?

11条回答
  •  旧巷少年郎
    2020-11-29 16:53

    This workaround in Python may help some people. First convert json or csv to dataframe using Pandas, then convert dataframe to dictionary and upload dictionary to firestore.

    import firebase_admin as fb
    from firebase_admin import firestore
    import pandas as pd
    
    cred = fb.credentials.Certificate('my_credentials_certificate.json')
    default_app = fb.initialize_app(cred)
    db = firestore.client()
    
    df = pd.read_csv('data.csv')
    dict = df.to_dict(orient='records')
    
    my_doc_ref = db.collection('my_collection').document('my_document')
    my_doc_ref.set(dict)
    

    There could be similar workarounds in javascript and other languages using libraries similar to Pandas.

提交回复
热议问题