google-cloud-firestore

Limit a number of documents in a subcollection in firestore rules

久未见 提交于 2020-01-13 11:22:50
问题 My request is pretty simple in appearence : limiting the number of documents in a subcollection using Firestore Rules. I already know that it is possible to know the size of an array using .size() . So, you may ask why I am not using an array to store my items ? Well, I want a "normal" user to not be able to update my parent document field but to be able to add a document to my subcollection. I already tried to do this : match /slots/{slot} { allow read: if true; allow write: if getRole() ==

Cloud Functions - Cloud Firestore error: can't get serverTimestamp

て烟熏妆下的殇ゞ 提交于 2020-01-13 10:35:10
问题 Cloud Functions - Cloud Firestore error: can't get serverTimestamp const admin = require('firebase-admin'); exports.userlog = functions.firestore .document('user/{userId}') .onUpdate((change, context) => { const db = admin.firestore(); //var timestamp = db.FieldValue.serverTimestamp(); var timestamp = db.ServerValue.TIMESTAMP; ... return db.collection('userlog').add( { userId : previousValue.userId, ... timestamp: timestamp }).then(ref => { return console.log('Added document with ID: ', ref

Creating user in Firebase gives me an error

大兔子大兔子 提交于 2020-01-13 06:08:26
问题 So I'm following a Savvy Apps tutorial in order to learn Vue.js. This tutorial uses Firebase with Firestore. Since Firestore is in Beta (as the tutorial says), changes might happen - and I think that might be the case here. In any case, I'm trying to sign up a new user. I fill out the form and click 'Sign up' and I get this error message: Error: Function CollectionReference.doc() requires its first argument to be of type string, but it was: undefined But looking in Firebase, I see that the

Flutter: Firestore transaction crashes only on physical iOS device

早过忘川 提交于 2020-01-13 05:59:25
问题 I have a simple transaction that updates a Firestore document. It works correctly on Android devices, Android Emulators and iOS emulators, but crashes on a physical iOS device : Firestore.instance.runTransaction((Transaction tx) async { DocumentSnapshot docSnapshot = await tx.get(docRef); tx.update( docRef, { 'title':'A Title' }, ); } Error: -[NSError init] called; this results in an invalid NSError instance. It will raise an exception in a future release. Please call errorWithDomain:code

How to update Flutter Cards in StreamBuilder without reseting state?

强颜欢笑 提交于 2020-01-13 05:26:09
问题 I got the StreamBuilder to work properly. 1 thing, every time 1 of the elements change the entire list resets. So for example each Card has a counter that I would like to see add and subtract without the screen changing. How can I do this? Here is my code (updated with full file stack) ... final FirebaseAuth _auth = FirebaseAuth.instance; final fb = FirebaseDatabase.instance.reference(); final falQuery = fb.child('NumberOnes').orderByChild('Value'); final streamQuery = fb.child('NumberOnes')

If persistence is enabled, what counts as read operations when data exists in cache?

南笙酒味 提交于 2020-01-13 04:43:27
问题 If the listener is disconnected for more than 30 minutes (for example, if the user goes offline), you will be charged for reads as if you had issued a brand-new query. Does this still apply if persistence is enabled? Situation 1: App is offline for over 30 minutes. Persistence is enabled and reads data from cache. Does reading documents from cache count as read operations? Situation 2: App is online but no added/modified/deleted operations occur. Persistence is enabled and all data exists in

Firebase Firestore toObject() with Kotlin

血红的双手。 提交于 2020-01-12 12:48:31
问题 I try to use Firebase Firestore in a Kotlin project. Everything is going fine except when I want to instantiate an object with DocumentSnapshot.toObject(Class valueType). Here is the code : FirebaseFirestore .getInstance() .collection("myObjects") .addSnapshotListener(this, { querySnapshot: QuerySnapshot?, e: FirebaseFirestoreException? -> for (document in querySnapshot.documents) { val myObject = document.toObject(MyObject::class.java) Log.e(TAG,document.data.get("foo")) // Print : "foo" Log

Cloud Firestore: Filter based on object content (via Flutter)

ⅰ亾dé卋堺 提交于 2020-01-12 05:40:06
问题 I have the following Firestore setup in use: Now I'd like to receive all documents where the current user (uid given) is in the users object/list. users is an object of references to thje users collection. Ideally I would want to use this filter from Flutter with the cloud_firestore package, however for now I'm just interested if this is possible at all. 回答1: I found this post which explains, that is not currently possible how I imagined it. I altered my setup to this: I can now use this

FirebaseFirestore different between OnCompleteListener, OnSuccessListener, OnCanceledListener and OnFailureListener

和自甴很熟 提交于 2020-01-11 14:03:12
问题 Can someone explain me how these Listener are different from each other? AFAIK, If I use OnCompleteListener() I can check if task complete or not and if it complete I can still check that it success or not. I confuse that when task failed. it happens because task not complete or task not success or it can occurs in both case. And how OnCanceledListener work? When it will be called? and what is the meaning of "Called when the Task is canceled successfully."? Please explain me, I confuse of

How to return a list from Firestore database as a result of a function in Kotlin?

空扰寡人 提交于 2020-01-11 13:48:09
问题 I'm building an app for a friend and I use Firestore. What I want is to display a list of favorite places but for some reason, the list is always empty. I cannot get the data from Firestore. This is my code: fun getListOfPlaces() : List<String> { val places = ArrayList<String>() placesRef.get().addOnCompleteListener { task -> if (task.isSuccessful) { for (document in task.result) { val name = document.data["name"].toString() places.add(name) } } } return list; } If I try to print, let's say