Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increment Firestore field value in python?

shard_ref.update("count", firebase.firestore.FieldValue.increment(1));

I am looking for way to increment and update in python, I am not abe to even update it with a predefined value in python. the doc doesn't specify any python samples. I am using firebase_admin sdk like this,

import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore

for more check docs https://firebase.google.com/docs/firestore/solutions/counters

like image 273
ishandutta2007 Avatar asked Nov 06 '22 17:11

ishandutta2007


1 Answers

Unfortunately (to me it just doesn't feel right), adding support for transforms in your codebase means you have to use google-cloud-firestore next to firebase_admin.

You can then use Transforms such as Increment, ArrayRemove, etc.

Sample code:

from google.cloud.firestore_v1 import Increment
# assuming shard_ref is a firestore document reference
shard_ref.update({'count': Increment(1)})
like image 188
LaundroMat Avatar answered Nov 15 '22 08:11

LaundroMat