Posts

Showing posts with the label Google Cloud Firestore

Add Field Separately To Firestore Document

Answer : Build a DocumentReference to the document you want to update, then use the update() method on the DocumentReference to indicate only the fields to be added or changed. Pass it an object with only properties that match the fields to add or change.

Angular 5, NullInjectorError: No Provider For Service

Answer : You need to add TesteventService under providers under imports in your app.module.ts providers: [ TesteventService ] Annotate your service class with - @Injectable({ providedIn: 'root' }) The service itself is a class that the CLI generated and that's decorated with @Injectable() . By default, this decorator has a providedIn property, which creates a provider for the service. In this case, providedIn: 'root' specifies that Angular should provide the service in the root injector.

Angular 6 - Getting Download URL For Firebase Storage File After Uploading

Answer : You should add a finalize() to the pipe, something like: this.task.snapshotChanges().pipe( finalize(() => { this.downloadURL = this.ref.getDownloadURL(); // <-- Here the downloadURL is available. }) ).subscribe(); In the finalize() step, the downloadURL is available, so u can grab him from the ref asynchronously. --UPDATE You said you are using Angular 6, so I assume you are using the last version of firebase. They change getDownloadURL() to Observable from Task, So to get the actual URL you just have to subscribe. this.task.snapshotChanges().pipe( finalize(() => { this.ref.getDownloadURL().subscribe(url => { console.log(url); // <-- do what ever you want with the url.. }); }) ).subscribe();

Convert Firestore DocumentSnapshot To Map In Flutter

Image
Answer : As per our discussion snapshot is not a DocumentSnapshot it is AsyncSnapshot to get the DocumentSnaphot use snapshot.data to get the actual map you can use snapshot.data.data Needed to simplify for purpose of example class ItemsList extends StatelessWidget { @override Widget build(BuildContext context) { // get the course document using a stream Stream<DocumentSnapshot> courseDocStream = Firestore.instance .collection('Test') .document('4b1Pzw9MEGVxtnAO8g4w') .snapshots(); return StreamBuilder<DocumentSnapshot>( stream: courseDocStream, builder: (context, AsyncSnapshot<DocumentSnapshot> snapshot) { if (snapshot.connectionState == ConnectionState.active) { // get course document var courseDocument = snapshot.data.data; // get sections from the document var sections = courseDocument['sections']; // build lis...

Console.log On Firebase Cloud Functions Simply Not Logging.

Answer : Ok, the problem ended up being that the function wasn't deploying properly. What had happened was due to some typescript/firebase config issue - the new code was being compiled to a location that wasn't what firebase was looking for. When deployed the code - some old compiled code was still there to be deployed. The moral of the story here is: make sure you delete your dist/build/lib directory before deploying - as that will cause an error if firebase is looking in the wrong place. In case someone wastes as much time as I did. It turned out I was logged into the wrong firebase project ‍♂️. firebase projects:list Your current project will be highlighted in blue with "(current)" beside it. If you need to change project: firebase use insert-project-id-here

Can Firestore Update Multiple Documents Matching A Condition, Using One Query?

Answer : Updating a document in Cloud Firestore requires knowings its ID. Cloud Firestore does not support the equivalent of SQL's update queries. You will always have to do this in two steps: Run a query with your conditions to determine the document IDs Update the documents with individual updates, or with one or more batched writes. Note that you only need the document ID from step 1. So you could run a query that only returns the IDs. This is not possible in the client-side SDKs, but can be done through the REST API and Admin SDKs as shown here: How to get a list of document IDs in a collection Cloud Firestore? Frank's answer is actually a great one and does solve the issue. But for those in a hurry maybe this snippet might help you: const updateAllFromCollection = async (collectionName) => { const firebase = require('firebase-admin') const collection = firebase.firestore().collection(collectionName) const newDocumentBody = { ...