google-cloud-firestore

FireStore fromSnapshot vs fromMap for reading DocumentSnapshot?

女生的网名这么多〃 提交于 2021-01-28 02:52:15
问题 I have been wondering which to use for reading a FireStore snapshot, as I can just use fromSnapshot as snapshot["fieldName"] works just fine. Now, I found an example in Google codelabs at https://codelabs.developers.google.com/codelabs/flutter-firebase/#10 Is this way the definitive way to go? Eg fromSnapshot, and then use fromMap for snapshot.data? What if I dont use fromMap? What am I losing? And then, I have also seen fromJson instead of fromMap... class Record { final String name; final

Unable to add information to Cloud Firestore

让人想犯罪 __ 提交于 2021-01-28 02:11:42
问题 The goal of the following code is to save data in Cloud Firestore from a android device(api 24) public class MainActivity extends AppCompatActivity { public static final String NUM_KEY="num"; public static final String SMS_KEY="sms"; private static final String TAG = "MainActivity"; private DocumentReference mDocRef = FirebaseFirestore.getInstance().document("android/websms"); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R

firestore : Missing or insufficient permissions

╄→гoц情女王★ 提交于 2021-01-28 02:06:42
问题 I'm using Role ( allow read ,write : if request.auth.uid != null ) when I logged in I get data it's ok , but when I log out the user I get the error : Missing or insufficient permissions. first I thought it was because of I didn't unsubscribe the Observable I tried (rxjs/operator/takeWhile) even if I used async pipe, I got the same error. 回答1: if you're logged out then request.auth.id == null, therefore, your read rule returns false. try changing to: allow read; allow create: if request.auth

How do i add more items on scroll in the listview?

落花浮王杯 提交于 2021-01-28 01:19:29
问题 This code here currently loads all the brews that are stored in the Firestore collection.. How can i load initially just 10 brews and then later on when the user scrolls down and reaches to the end of the list of 10 brews..it should load 10 more after the last brew..and the brews should be sorted according to the timestamp. class BrewList extends StatefulWidget { @override _BrewListState createState() => _BrewListState(); } class _BrewListState extends State<BrewList> { List<Brew> brews = [];

Firestore: Reading data with references do increase in number of requests?

≯℡__Kan透↙ 提交于 2021-01-28 01:04:21
问题 When documents on firestore is read, firestore wont give references data, if any. so currently I am requesting firestore for data from reference path. Do this increase in number of requests to server, eventually decrease in performance and increase in pricing ? How storing references is helpful in terms of requesting data from server ? 回答1: Reading a document that has a reference counts as a read of that document. Reading the referenced document count as a read of another document. So in

Pass user auth to Firestore from Cloud functions

ぃ、小莉子 提交于 2021-01-28 00:23:01
问题 So I'm trying to build an http endpoint using a Cloud function. This cloud function is only invoked after the user signs in. So I can pass the user token and verify it on the server side. I understand how to do this. I also have security rules on my Firestore collections with authorization rules set up using request.auth.uid. This also just works if I use the firebase web sdk. But my question is - how do I use the same authorization rules via cloud functions? I don't want to rewrite my auth

Firebase Cloud Firestore REST api authentication with only WEB API key?

[亡魂溺海] 提交于 2021-01-28 00:00:46
问题 I'm trying to insert a new record in a Firebase Cloud Firestore database via its REST API and curl. Reading from the database is working as expected since the operation is public. Create operation is not listed in the database rules and it is performed only server side, but I'm unable to do it using only the project API KEY. Take for example the following curl request: curl --header "Content-Type: application/json" \ --request POST \ --data '{"fields":{"myField": {"stringValue": "test"}}}' \

Firebase cloud function typescript error “Not all code paths return a value”

前提是你 提交于 2021-01-27 23:48:39
问题 I am using firebase cloud function and firestore transaction to decrease the available quantity of product based on purchases. At the time of deploy it returns the error "error TS7030: Not all code paths return a value" Here is the code import * as functions from 'firebase-functions'; import * as admin from 'firebase-admin'; admin.initializeApp(); const db = admin.firestore() exports.newOrder = functions.firestore .document('orders/{orderId}') .onCreate(async (snap, context) => { try { const

Securely saving data in Firestore

别说谁变了你拦得住时间么 提交于 2021-01-27 21:45:42
问题 The Firestore documentation shows examples of how to secure data using Firestore security rules based on the request.auth.uid field. These typically look something like this: service cloud.firestore { match /databases/{database}/documents { match /stories/{storyid} { // Only the authenticated user who authored the document can read or write allow read, write: if request.auth.uid == resource.data.author; } } } That makes perfect sense. What I don't understand (and doesn't appear to be shown

Order by a number field where a timestamp is on a given date in Cloud Firestore?

时光毁灭记忆、已成空白 提交于 2021-01-27 21:23:42
问题 In my Firestore database I have some documents in a collection that look like this: { name: "Item 1", count: 2, timestamp: January 29, 2018 at 3:43:12 PM UTC-8 } I'm trying to query this collection such that the documents are ordered by count in descending order, AND have their timestamp 's date equal to today's date. Using Moment.js, this is the query I have so far: const startOfToday = moment().startOf('day').toDate(); const endOfToday = moment().endOf('day').toDate(); const query = db