google-cloud-firestore

Firebase Firestore subcollection of documents from document

北慕城南 提交于 2021-01-28 08:18:32
问题 In my collection's SnapshotListener, I have am looping through the documents with: for (DocumentChange doc : queryDocumentSnapshots.getDocumentChanges()) { if (doc.getType() == DocumentChange.Type.ADDED) { String somestr = doc.getDocument.getString("someField"); // retrieve collection here } } And within each document in the for loop, let's call it doc , I have another collection of documents on Cloud Firestore. I would like to retrieve all documents (each of which just has a single String

How to update or set property of firestore document after .onCreate cloud function trigger

家住魔仙堡 提交于 2021-01-28 07:34:33
问题 I'm currently trying to integrate Stripe with my Firebase's Cloud Firestore db through using Cloud Functions for Firebase. The onCreate trigger is happening correctly but I also want it to update or set a specific field called "customer_id" into the right document in my Users collection. I think something is a little off about how I write my function since I'm not the most experienced with javascript. I've also tried return admin.firestore().ref(`Users/${user.uid}/customer_id`).set(customer

Firestore realtime listener to multiple documents async await

随声附和 提交于 2021-01-28 07:21:05
问题 I am wondering if the realtime listener for Firestore supports async await instead of promise? The documentation suggests: var unsubscribe = db.collection("cities").where("state", "==", "CA").onSnapshot(function(querySnapshot) { var cities = []; querySnapshot.forEach(function(doc) { cities.push(doc.data().name); }); console.log("Current cities in CA: ", cities.join(", ")); }); unsubscribe(); Could I write the above realtime listener using async await ? I tried the following and the listener

Write data in to nested object in firebase firestore

我的未来我决定 提交于 2021-01-28 07:10:01
问题 I have a data structure that looks as follows: This is the top level of the collection: I want to write to increment the field count but I can't do it. I've tried so many different methods that I'd rather not go through all of them. The closest I've gotten was through: const pageRef = admin.firestore().collection("pages").doc(image.page); pageRef.set( { [`images.${image.position}.count`]: admin.firestore.FieldValue.increment( 1 ), }, { merge: true } ); But that leaves me with: Please help.

Cloud Firestore: Add collection and sub collection in one go

为君一笑 提交于 2021-01-28 06:44:21
问题 Reading the documentation I can't see a way if this is possible in a sensible way. I'm trying to create a document team with a sub document of member . And what I'm really trying to achieve is an in-complex way of structuring read/writes/updates on collections and sub collections. async createTeam(newTeam, foundingTeamMember) { const teams = db.collection('teams'); const teamRef = await db.collection('teams').add(newTeam); const memberRef = await teams.doc(companyRef.id) .collection('members'

Ionic Increment Firestore Value

微笑、不失礼 提交于 2021-01-28 05:48:36
问题 I was wondering if there was a way to increment a value in Firestore with Ionic. For example, a like button and when clicked a field value 'likes' adds +1 onto the existing value. I saw examples with 'transactions' where this is done but it was with the Realtime Database rather than the Cloud Firestore. I looked further and could not find any documentation regarding Firestore. Is there anyway to pull this off without pulling the existing value from the snapshot first? Thanks, Troy 回答1: There

firebase batch updates and onWrite trigger synchronisation

送分小仙女□ 提交于 2021-01-28 04:41:16
问题 I have an issue with synchronizing two Firebase cloud functions, the first one performing a batch update on multiple documents and the second one triggered by an onWrite trigger on one of those documents. For illustration, let us say I have two documents A and B (in two separate collections). A first cloud function updates both documents A and B with a firestore WriteBatch (both documents are successfully updated); The write in document B triggers another cloud function (with an onWrite

Firebase getDocument (querySnapshot) is not working

你说的曾经没有我的故事 提交于 2021-01-28 04:08:48
问题 I'm facing an issus with the Firebase Snapshot. I conntected my Fierbase account succesfully with my Xcode project. I am capable to change data in my Firestore cloud. But I can't read it. Here is my function: class UserService{ static func CheckIfMoreThanOneUserIsLoggedIn() -> Bool{ var BoolenToReturn:Bool? let AuthUser = Auth.auth().currentUser let userId = AuthUser!.uid let localDeviceString = Constants.UserDefaultsStorage.string(forKey: userId) // LocalDeviceString is generated (20 random

Firebase querySnapshot not updating realtime with where condition

允我心安 提交于 2021-01-28 03:41:54
问题 I am using cloud firestore with flutter to store the chat and using where condition to get the chats. the documents returns correctly but when the new data is added the chat list will not update in realtime. How the chat is stored:- collection -> message {message, timestamp, sentBy,sentTo} are the message fields the query is firestore .collection('chats_v2') .where('sentBy', isEqualTo: 'abc') .where('sentTo', isEqualTo: 'xyz') .orderBy('timestamp') .snapshots(); The Chat loads perfectly for

Convert DatetimeWithNanoseconds to date format in python firestore

别说谁变了你拦得住时间么 提交于 2021-01-28 03:24:51
问题 I am trying to convert a firestore timestamp into milliseconds or a date format using python to perform a calculation using this date. Trying to parse it to date returns. TypeError: strptime() argument 1 must be str, not DatetimeWithNanoseconds. How can I convert a Firestore timestamp into milliseconds/date format in python? I need this to perform a calculation. docs = db.collection(u'status').stream() for doc in docs: doc_data = doc.to_dict() # TypeError: strptime() argument 1 must be str,