def deleteAllDocsFromCollection(db):
    collection = input('Collection name -> ')
    documents = fireclient.readAllDocsFromCollection(db, collection)
    for index, uid in enumerate(documents):
        print(f'{index} => deleting {documents[index]} from {collection}')
        db.collection(collection).document(documents[index]).delete()
    print('Finished')
Beispiel #2
0
def addSameFieldDifferentValueToAllDocsInCollection(db, data):
    if len(data) != 0:
        collection = input('Collection name -> ')
        field = input('Field name -> ')
        for index, doc in enumerate(data):
            print(f'[{index}] => {doc}')
        print('\n')
        for index, uid in enumerate(data):
            print(f'[{index}] => adding {uid} in doc {data[index]}')
            content_ref = db.collection(collection).document(data[index])
            content_ref.set({field: data[index]}, merge=True)
    else:
        contents = []
        collection = input('Collection name -> ')
        field = input('Field name -> ')
        documents = fireclient.readAllDocsFromCollection(db, collection)
        for index, doc in enumerate(documents):
            print(f'[{index}] => {doc}')
        print('\n')
        answer = input('Do you want to read data from files? (y/N) -> ')
        if answer == 'y':
            print('Reading from local json file')
            for index, uid in enumerate(documents):
                jsonvalue = str(fireclient.geturl(uid))
                print(f'{index} => adding {jsonvalue} to {uid}')
                field_ref = db.collection(collection).document(
                    documents[index])
                field_ref.set({field: jsonvalue}, merge=True)
        else:
            for index, uid in enumerate(documents):
                content = input('Content -> ')
                content_ref = db.collection(collection).document(
                    documents[index])
                content_ref.set({field: content}, merge=True)
    print('Finished')
def deleteFieldFromAllDocsInCollection(db):
    collection = input('Collection name -> ')
    field = input('Field name -> ')
    documents = fireclient.readAllDocsFromCollection(db, collection)
    for index, uid in enumerate(documents):
        print(
            f'{index} => deleting {field} from {collection} in {documents[index]}'
        )
        delete_ref = db.collection(collection).document(documents[index])
        delete_ref.update({field: firestore.DELETE_FIELD})
    print('Finished \n')
Beispiel #4
0
def addFieldToAllDocsInCollection(db):
    collection = input('Collection name -> ')
    documents = fireclient.readAllDocsFromCollection(db, collection)
    for index, uid in enumerate(documents):
        print(f'[{index}] => {uid}')
    print('\n')
    field = input('Field name -> ')
    content = input('Content -> ')
    for index, uid in enumerate(documents):
        print(f'%s{index} => adding {field} to doc {documents[index]}' % good)
        pedidos_ref = db.collection(collection).document(documents[index])
        pedidos_ref.set({field: content}, merge=True)
    print('Finished')
Beispiel #5
0
def adduidArrayToField(db, array):
    collection = input('Collection name -> ')
    documents = fireclient.readAllDocsFromCollection(db, collection)
    for index, doc in enumerate(documents):
        print(f'[{index}] => {doc}')
    print('\n')
    answer = input('Do I add same field to all docs? (y/N) -> ')
    if answer == 'n':
        field = input('Field name -> ')
        array_ref = db.collection(collection).document(doc)
        array_ref.set({field: array}, merge=True)
        print('Finished')
    else:
        field = input('Field name -> ')
        for index, uid in enumerate(documents):
            print(f'%s{index} => adding {field} to doc {documents[index]}' %
                  good)
            array_ref = db.collection(collection).document(documents[index])
            array_ref.set({field: array}, merge=True)
    print('Finished')