google-cloud-firestore

Firestore Cloud Function - Value of external variable not recognized in .then()

心已入冬 提交于 2021-02-11 14:19:30
问题 I am new to Firestore cloud functions, and trying to run a simple function that triggers onWrite() in one collection and based on that, updates value in different one. I am hitting roadblock where value of variable (const array actually), is not recognized inside the ...get().then(snapshot) => {} method. As I understand the outer variable's scope should be inside as well, shouldn't it? What am I doing wrong? Research on this topic led me to concept of Promises, and I tried creating promise

Flutter Firebase How to make Sequential Query

喜欢而已 提交于 2021-02-11 14:13:59
问题 I am developing a forum application. There are two collections related to user information and topic information in my Firebase database. In the forumTopics collection, I keep the data on each forum topic. When I make a Firebase query, I want to get the data of this topic along with the data of the user corresponding to the topicAuthorUID value. For example, I want to extract the name, avatar information from the document of the user whose topicAuthorUID value is XXX in the userData

swift - Retrieving firebase Image into ImageView

牧云@^-^@ 提交于 2021-02-11 14:13:58
问题 Hello everyone I am struggling with retrieving my image from firebase into my Image view. The first thing I do is create a method to retrieve the photo data in an array here is that code: class PhotoService { static func retrievePhotos(completion: @escaping ([Photo]) -> Void) { //get a databas refrence let db = Firestore.firestore() //get data from "photos" collection db.collection("photos").getDocuments { (snapshot, Error) in //check for errors if Error != nil { //error in retrieving photos

swift - Retrieving firebase Image into ImageView

穿精又带淫゛_ 提交于 2021-02-11 14:11:45
问题 Hello everyone I am struggling with retrieving my image from firebase into my Image view. The first thing I do is create a method to retrieve the photo data in an array here is that code: class PhotoService { static func retrievePhotos(completion: @escaping ([Photo]) -> Void) { //get a databas refrence let db = Firestore.firestore() //get data from "photos" collection db.collection("photos").getDocuments { (snapshot, Error) in //check for errors if Error != nil { //error in retrieving photos

Will cost only getting the size of a collection of 1000 docs as 1000 read?

寵の児 提交于 2021-02-11 14:02:27
问题 I am confused about Cloud firestore cost. I want to get the size of a collection of 1000 docs, and I am not reading every doc data, so will it cost me as 1000 read or 1 read? db.collection(`users/${user}/followers`) .get().catch(onErr).then(followers=> { console.log('followers length: ', followers.size); }); I have 1000 docs in followers collection, so as you can see I am only reading the length of collection, so how much will cost me ?? 1000 read or 1 read? 回答1: If in the followers

How to manage add and update data in Firebase

喜欢而已 提交于 2021-02-11 14:01:29
问题 I'm using Flutter. I would like to add data at first. If email or uid had been registered, I want to update data01/02 or add data01/02. How can I specify the initial data. _firestore.collection('members').add({ 'uid': loginUser.uid, 'email': loginUser.email, 'data01': { 'name': name, 'img_url': 'https://www.xxx.xxx/xxx.png', 'data02': { 'phone': phone, } } Please give me advice. 回答1: Assuming you set your document name to your loginUser.uid you can use: String rawJson = '{ "email": loginUser

Flutter Firebase Loop over collection in a document [duplicate]

自作多情 提交于 2021-02-11 14:01:10
问题 This question already has an answer here : Using Flutter Firestore plug in, do something for each sub collection in a document (1 answer) Closed last year . I have this path in my Database: /messages/tT2Q16n1FMZoTNZQOejtWuJdCmD2/ZqihbgR7skcytLAe88fQecmxcIc2-tT2Q16n1FMZoTNZQOejtWuJdCmD2/1579626761580 and from here I have to get content . I am trying this: var snapshot = Firestore.instance.collection('messages').document(user.id).snapshots(); but how can I loop over these items and get content

Is it possible to use Where In with a Collection Group query in Firestore?

纵然是瞬间 提交于 2021-02-11 14:00:40
问题 In my database: -Users(Top level collection): ---user1(doc): ----------pets(sub collection): --------------pet1(doc) --------------pet2(doc) ---user2(doc): ----------pets(sub collection): --------------pet3(doc) --------------pet4(doc) If i have a List of ids: list("pet2", "pet3", "pet4) Is there a way to do something like this and get a back a List of DocumentsSnapshots? firestore.collectionGruop("pets")whereIn(FieldPath.documentId(), list) It works with a root collection but i dont know if

Query Firestore collection based on negation

岁酱吖の 提交于 2021-02-11 13:38:46
问题 We are developing a messaging system where the users are able to block each other. This means we need the ability to query message where the author is not blocked. Pseudo: Select * from messages where author_id not in {list_of_blocked_ids} Since Firestore does not support array_not_contains or any other negation-methods we are quite unsure how to structure this data to be able to make this query. Any help structuring this information about blocked users is appreciated. 回答1: To solve this

Why can't I reach the variable inside an initState in flutter?

只谈情不闲聊 提交于 2021-02-11 13:37:27
问题 I am trying to use a variable that I got from firestore by using a void finction and when I print it in the same function or another function it gets it but when I use it in an initState it gives me null HELP! the var I want is userType. code : getuserData form firebase: void getUserData() async { try { firestoreInstance .collection('Users') .document(usernameController.text) .get() .then((value) { setState(() { email = (value.data)['email']; password = (value.data)['password']; gender =