def update_sensores(collection, document, item1, item2, data1, data2):
    # [REFERENCE collection (AND/OR document)]
    doc_ref = db.collection(collection).document(document)
    # [UPDATE MULTIPLE ITEMS]
    doc_ref.update({
        item1: data1,
        item2: data2
    }, cloudfirestore.CreateIfMissingOption(True))
def update_document(document_path, update_json, create_if_missing=False):
    doc_ref = db.document(document_path)
    doc_ref.update(update_json,
                   firestore.CreateIfMissingOption(create_if_missing))

    # for nested jsons use parent.child in json update rather than parent : { child }
    # for timestamp updates use firestore.SERVER_TIMESTAMP
    # to delete a field, add "attribute_name" : firestore.DELETE_FIELD in json

    return {"new_json": doc_ref.get(), "doc_id": doc_ref.id}
def update_nested_create_if_missing(collection, document):
    # [REFERENCE collection (AND/OR document)]
    parceiros_ref = db.collection(collection).document(document)
    parceiros_ref.set({
        'nome': 'Cliente',
        'pulseiras_adotadas': {'200000001', '200000002'},
        'contato': '*****@*****.**'
    })
    parceiros_ref.update(
        {
            'idade': 'T-Access',
            'pulseiras_adotadas.200000002': '200000022'
        }, cloudfirestore.CreateIfMissingOption(True))
Example #4
0
def update_nested_create_if_missing(collection, document):
    # [REFERENCE collection (AND/OR document)]
    admins_ref = db.collection(collection).document(document)
    admins_ref.set({
        u'name': u'Cliente',
        u'artowned': {u'200000001', u'200000002'},
        u'contact': u'*****@*****.**'
    })
    admins_ref.update(
        {
            u'age': u'T-Access',
            u'artowned.200000002': u'200000022'
        }, cloudfirestore.CreateIfMissingOption(True))
Example #5
0
    def commit(self, is_merge=False):
        if self.__document__ is None:
            logging.warning('need load `__document__` before commit')
            return False

        if self.__data__ is None:
            logging.warning('can not commit to firestore since date is None')
            return False

        for key in self.__is_not_none__:
            if key not in self.__data__:
                logging.warning('%s can not be none' % key)
                return False

        if is_merge:
            self.__document__.update(
                self.__data__,
                firestore.CreateIfMissingOption(True)
            )
        else:
            self.__document__.set(self.__data__)
        self.__document_name__ = self.__document__.id
        return True
def update_create_if_missing():
    db = firestore.Client()
    # [START update_create_if_missing]
    city_ref = db.collection(u'cities').document(u'BJ')

    city_ref.update({u'capital': True}, firestore.CreateIfMissingOption(True))