Angularfire2 getting nested data from Firestore database - angularfire2

I'm trying to develop a small application with a Firestore backend and angularfire2 in the frontend. I created some data and now I'm trying to get the right reference to them. These are my data:
Firestore data
I'm trying to get the reference to them with:
this.afs.collection("accounts").doc(accountId).collection("conversations").doc(conversationId).valueChanges().subscribe(conversation => {...}
(afs is the Angularfirestore from angularfire2/firestore)
But this results in no data in the conversation-object.
If I do this.afs.collection("accounts").doc(accountId)... I get the Account-Document as expected.
But I can't get deeper into the object.
I'm trying the same as described here:
https://firebase.google.com/docs/firestore/data-model
I'm using Firestore and Angularfire2 (5.0.0-rc.4)

I think you're doing everything correct apart of declaring the subcollection. Your "conversations" subcollection is not a Collection, it is a "field" of the document. That's why you can not access it in the way you're trying to access it.

Related

Why does Multiple media field returns same image?

I am working on a sample blog web app using Gatsby and Strapi. To test the multiple-media capability:
I created a test dataset, where the Collection Type definition was a single "Name" field and a field for multiple media.
name: Text, images: List[Media]
Then, I created few entries, expecting to use the following graphql query to retrive the data from strapi: query
However, the publicURL property for each returned row is the same image url - the first uploaded image. As a result, the web app displays the same image for all three records.
Based on posts online, I suspected it might be a cache issue and tried gatsby clean multiple times and gatsby develop. However, the images are still getting mixed up.
I'm stuck on identifying why this might be happening. Does anyone have any thoughts on what could be the problem? I'd appreciate the insight.
Do not pull formats just get full lists as an object.
Modify your GraphQL query then handle lists inside gatsby.
console.log(typeof(lists))

How to get data from the user documents from firestore? (Flutter)

I'am new in flutter_programming.
I want to get the data from the user.document. I have already created a new collection if I sign up in my application.
I use this command snapshot.data.document[][] (Streambuilder) for getting data from firestore.
But I have to declare the first array to access the document.
So I can't access automatically the user document.
To get the data from Firestore you need to use the stream,
Stream<QuerySnapshot> get data {
return Firestore.instance.collection('yo').snapshots().map(_taskListFromSnapshot);
}
}

Laravel pluck with paginate

So, I've a ERM with two database connected in a same laravel app. I'm trying to pull up all the IDs with pluck which is working fine but not being able to paginate. For an instance,
$newsTagSaved = NewsTag::latest()->pluck('post_id');
This works just as fine. But this pulls up way more information than I need. I'm looking for something like:
->pluck('id')->paginate(12);
This way I'm not loading data in ajax that I don't need since it will query unnecessary data on every ajax call.
Thank you!

How to fetch data from relationship in strapi.js?

I have created two content type builder which are category and sub-category respectively. While adding sub-category I had define one relationship which is one-to-many.
After creating successfully, I found that the basic CRUD API has been created and it works fine.
Now I need to find data like if I pass category-id then it has to return me it's all sub-category list.
Well, for this I can also write API manually, But I thought that strapi provides a feature of relationship though it may have some way to fetch data from the relationship table. In my app, I had set up a project with MySQL.
Expected output: Need a way to fetch data from a relation without writing custom API. Looking for inbuilt feature of strapi.
You have to use deep filtering.
📚Here is the documentation https://strapi.io/documentation/3.0.0-beta.x/guides/filters.html#deep-filtering
So you will be able to do /categories?sub-category.id=[your id]

How to improve Angular2 rendering performances when accessing a backend server?

I have a service which is responsible for getting the data from a backend.
The data is shown via a component in its nginit method. It is shown in a table (html table).
I would like to be able to manipulate data without having to reload it each time in my table : ex : delete a row, add a row ... I want all of this very fluid. The data is coming from a database.
So my question is :
Should my service return an observable or an array ?
Is nginit the best place to show my table ?
How should I do things maybe to manage everything in memory? I do not know.
Thanks for any advice.
I would save the data into an array then use lodash to manipulate it.
You could edit, delete, and add rows using lodash's built in functions. When you want to save the data to the backend you would then post the array back to the server. This will keep backend requests to a minimum which will help your performance.
For example you could delete elements from the array using the remove function, https://lodash.com/docs/4.17.4#remove
Lodash can be setup like this https://medium.com/#gtsopour/importing-lodash-into-angular-2-typescript-application-94590365f46d#.9mdcdjnac
Of course you could do this all using raw js though but I find Lodash very rich and easy to use.

Resources