Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save document with type "Reference" in Firestore using Python

How to save in firestore using python, a document with exactly type reference

I know in js, you can doing something like this:

let data = {
  name: 'productName',
  size: 'medium',
  userRef: db.doc('users/' + firebase.auth().currentUser.uid)
};
db.collection('products').add(data);

userRef being the reference.

what's in python the way to doing: db.doc('users/' + firebase.auth().currentUser.uid)

like image 802
Andresse Njeungoue Avatar asked Jul 29 '26 11:07

Andresse Njeungoue


1 Answers

Passing the document reference as the value in set() works. Example:

reference = db.collection('Company').document('Apple') 
db.collection('Product').document('iPhone').set({"company_id":reference},merge=True)
like image 161
Samrat Thapa Avatar answered Jul 30 '26 23:07

Samrat Thapa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!