Can we query a firebase snapshot? - swift

Once a query data from firebase, can we then query it once more on the snapshot level?
I basically want to query my data twice
1- Genre: “Arts & Humanities”
2-Timestamp
Just brainstorming ideas since we can’t query twice. I’m also limited on how I can structure my data

Once you execute a query against the Firebase Realtime Database, you get a DataSnapshot that contains all the data that matches the query. So while you can continue to filter the data in your Swift code, you cannot execute another query against the snapshot. You'll instead have to loop through the data, and filter it yourself.
Note however that might be able to meet your query needs with a single query. Firebase Database queries can only order/filter on a single property. In many cases it is possible to combine the values you want to filter on into a single (synthetic) property. For example, you could add a property "Genre_Timestamp": "Arts & Humanities_1581309158055" and order/filter on that. For another example of this and other approaches, see my answer here: Query based on multiple where clauses in Firebase

Related

Mongoose skip and limit (MongoDB Pagination)

I am using skip and limit in mongodb mongoose it returns random documents.
Sometimes it returns same documents.
I am trying to get limit number of documents and after skip i want to get next limit documents.
I guess you are trying to use the pagination concept here. In both SQL and NoSQL, the data must be sorted in a specific order to achieve pagination without jumbled data on each db call.
for example:
await Event.find({}).sort({"createdDate": 0}).skip(10).limit(10);
I'm trying to fetch the 10-20 data in the above case, which is sorted using createdDate. So, the data won't shuffled while fetching, unless you insert or delete the data.
I hope this answers your question

Firebase Flutter: how to quay Real time database nested data list

i am trying to display all this shops inventory data and filter by category/name/price/etc..
i can do this by using orderbyChild("Shop") and push all data in
to list and display/filter data but with large user data that
way can cause performance?
is their better way to get all this shops data and filter using
category /product name/price/etc...
Firebase Realtime Database queries look for values at a fixed path under each direct child node of the path that you query. They don't recursively search on all nodes under there. So, if you want to search across all shops, you'll have to (possibly additionally) store the data in a flat list.
Also see Firebase Query Double Nested

Flutter Firebase field string matching

So I'm creating this flutter project where I want to match 2 field from a different collection in firebase how should I do that? Like if the first data from the 1st field matches the data from the 2nd field return true
here it the example image
- and here is the 2nd example image
Firestore queries can only order/filter on data that is inside each document that they actually return. There is no way to order/filter in any value in another document, whether present in the results or not.
Usually you'll want to modify your data model to your use-case, typically by adding more data that allows this specific query. This is actually quite common in NoSQL databases, where you often end up expanding your data model to allow for specific use-cases. To learn more about data modeling in NoSQL databases, I recommend reading NoSQL data modeling and watching Todd's video series Get to know Cloud Firestore.

Firestore pagination of multiple queries

In my case, there are 10 fields and all of them need to be searched by "or", that is why I'm using multiple queries and filter common items in client side by using Promise.all().
The problem is that I would like to implement pagination. I don't want to get all the results of each query, which has too much "read" cost. But I can't use .limit() for each query cause what I want is to limit "final result".
For example, I would like to get the first 50 common results in the 10 queries' results, if I do limit(50) to each query, the final result might be less than 50.
Anyone has ideas about pagination for multiple queries?
I believe that the best way for you to achieve that is using query cursors, so you can better manage the data that you retrieve from your searches.
I would recommend you to take a look at the below links, to find out more information - including a question answered by the community, that seems similar to your case.
Paginate data with query cursors
multi query and pagination with
firestore
Let me know if the information helped you!
Not sure it's relevant but I think I'm having a similar problem and have come up with 4 approaches that might be a workaround.
Instead of making 10 queries, fetch all the products matching a single selection filter e.g. category (in my case a customer can only set a single category field). And do all the filtering on the client side. With this approach the app still reads lots of documents at once but at least reuse these during the session time and filter with more flexibility than firestore`s strict rules.
Run multiple queries in a server environment, such as cloud store functions with Node.js and get only the first 50 documents that are matching all the filters. With this approach client only receives wanted data not more, but server still reads a lot.
This is actually your approach combined with accepted answer
Create automated documents in firebase with the help of cloud functions, e.g. Colors: {red:[product1ID,product2ID....], ....} just storing the document IDs and depending on filters get corresponding documents in server side with cloud functions, create a cross product of matching arrays (AND logic) and push first 50 elements of it to the client side. Knowing which products to display client then handle fetching client side library.
Hope these would help. Here is my original post Firestore multiple `in` queries with `and` logic, query structure

Swift firestore get more than one collection's documents at same time?

How to get more than one collection's documents data?
my firebase tree is like :
"tahminler/'useruid'/'date as like (5.3.2018 or 6.3.2018)'/'documentID'/'Document data'"
so how to take all dates collection's documents in a function
and here is my firebase firestore console:
Firestore doesn't have a way to make a single query across multiple collecitons. You will have to query each collection individually, then merge the results in your client code.
If it's important to be able to make a single query for everything you need, considering restructuring or duplicating your data to suit that query.