google-cloud-firestore

Firestore - how to get the total number of records in a collection like we are doing in sql [duplicate]

…衆ロ難τιáo~ 提交于 2021-02-11 13:28:47
问题 This question already has answers here : Cloud Firestore collection count (17 answers) Closed 2 years ago . db.collection("cities").get().then(function(querySnapshot) { console.log(querySnapshot.size); }); but the problem is I am using pagination and load 30 records for each call. so I am unable to get the total numbers of records. Is there any way to get it ? like, we are doing in sql. 回答1: How to get the total number of records in a collection with Firebase ? The method numChildren() do

Firebase Firestore security rules - read all nested docs based on resource (but it's null)

别说谁变了你拦得住时间么 提交于 2021-02-11 13:05:35
问题 I think I'm doing something wrong but I can't figure which part... Thanks for all the clarification I can get. So I have a collection named Bases that looks like this: { "id1": { "name": "My base 1", "roles": { "idUser_123": { "name": "John" } } }, "id2": { "name": "My base 2", "roles": { "idUser_456": { "name": "Jane" } } } } idUser_123 log in and want to access his collection. So I do: db.collection('bases').get() And I use a match rule to make sure John is not reading Jane's bases. And

iOS app crashes when calling this function 2 times in a row (Firebase Storage, Flutter)

[亡魂溺海] 提交于 2021-02-11 12:51:47
问题 My app crashes when calling "_submit" function 2 times in a row. I can pick the picture from gallery and upload it to Firebase Storage but if I call it again the the whole app crashes. From this button : floatingActionButton: FloatingActionButton( onPressed: () => _submit(), Submit calls a Provider of type Database : Future<void> _submit() async { widget.database = Provider.of<Database>(context, listen: false); await widget.database .setPicture("regione/citta/comune/lavoro/IDArtista/profilo

Firestore with complex filter and composite indexes

ε祈祈猫儿з 提交于 2021-02-11 12:51:46
问题 I use Cloud Firestore and this is my data structure : Firestore-root | --- collection (collection) | --- uid (document) | --- name: some_name | --- some_fields: some_data | --- origin: [origin_1, origine_2, ...] <- List | --- category: [category_1, category_2, ...] <- List | --- meals: [meals_1, meals_2, ...] <- List | --- some_other_filters: [.....] <- List | --- all_categories: [origin_1:true, origine_2:true, meals_1:true, ....] I created the Map field all_categories to hold all different

iOS app crashes when calling this function 2 times in a row (Firebase Storage, Flutter)

◇◆丶佛笑我妖孽 提交于 2021-02-11 12:50:56
问题 My app crashes when calling "_submit" function 2 times in a row. I can pick the picture from gallery and upload it to Firebase Storage but if I call it again the the whole app crashes. From this button : floatingActionButton: FloatingActionButton( onPressed: () => _submit(), Submit calls a Provider of type Database : Future<void> _submit() async { widget.database = Provider.of<Database>(context, listen: false); await widget.database .setPicture("regione/citta/comune/lavoro/IDArtista/profilo

Get all doc data from collection seremon firestore

我的未来我决定 提交于 2021-02-11 12:48:58
问题 function Sermons() { const [{globalSeremon}, dispatch] = useStateValue() const [seremons, setSeremons] = useState([]) const [loading, setLoading] = useState(false) useEffect(() => { db.collection('sermons') .orderBy("date", "desc") .get() .then((snapshot) => { const localseremons = [] snapshot.forEach(doc => { localseremons.push(doc.data()) }) setSeremons(localseremons) }) .catch(e => console.log(e)) }) return ( <div> <Header/> <div className='container-lg seremon_container'> {seremons.map

Flutter Map markers not displaying

前提是你 提交于 2021-02-11 12:47:39
问题 import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:flutter/material.dart'; import 'package:geolocator/geolocator.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; class NewMap extends StatefulWidget { @override _NewMapState createState() => _NewMapState(); } class _NewMapState extends State<NewMap> { GoogleMapController _controller; Position position; Widget _child; Map<MarkerId, Marker> markers =

Trying to access FirestoreAdminClient from Cloud Run service using firebase-admin. ERROR: 7 PERMISSION_DENIED: The caller does not have permission

╄→尐↘猪︶ㄣ 提交于 2021-02-11 12:47:29
问题 I've got the following code for a an API endpoint that is supposed to trigger a Firestore backup using firebase-admin . This is how I'm initializing firebase-admin ; import * as admin from "firebase-admin"; admin.initializeApp({ credential: admin.credential.cert( SERVICE_ACCOUNT as admin.ServiceAccount )}); The service account key is a JSON I've downloaded using the default firebase-admin service account: This is the backup.ts API request handler. export const backupData: RequestHandler =

Firestore: Queries and Security (Swift)

不问归期 提交于 2021-02-11 12:29:34
问题 TL;DR How do you perform a query on a secure Firestore collection? In Firestore have the following Security Rule: service cloud.firestore { match /databases/{database}/documents { match /users/{userId} { allow read, update, delete: if request.auth.uid == userId; allow create: if request.auth.uid != null; } } } Currently, the document ID is the userId and there is also a field in each document with the userId. I can find the document if I go straight to a specific document using its document

Firestore use database/server time for query

允我心安 提交于 2021-02-11 12:29:01
问题 I have a collection in Firestore that contains a string for the next 365 days. It's effectively a codeword that our app needs to display on that particular day. We've noticed that if a user changes the date and comes back to the app, Firestore correctly returns the codeword for that day because our query uses today's date to query for the codeword. Previously, we had a bespoke API on a server that would fetch based on the server's time to ensure this couldn't happen. What would be the best