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

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.

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

Can you create a sub-collection from flutter?

I was wondering if you could create a sub-collection from within flutter to firestore. I've heard you need to add manually add a document or something like that before you can access a sub-collection from flutter, but I wanted to know if there was a work-around.
Something like this-> Firebase.Firestore.instance.collection('groups').doc(groupID).collection('posts').add('')
without having to manually add a document first. Thanks
In Firestore (all client platforms, not just Flutter), both collections and subcollections don't "exist" in the console unless there is at least one document in it. If you want a subcollection to "exist", simply write a document to it.
When the last document is removed from a collection or subcollection, it ceases to "exist" in the console (after you reload it).
Collections are not really an "thing" in firestore. Documents are a thing, and they happen to be organized under collections. Your app should not depend on collections or subcollections existing - it should depends on documents being returned from queries on those collections.
See also:
Is possible to check if a collection or sub collection exists?
How to check if Cloud Firestore collection exists? ( querysnapshot)
In Dart/Flutter, how can I find out if there is no Collection in the Firestore database?

Get all documents from firestore which contains a particular value in its subcollection

I have a collection say users and it has a subcollection vehicles(type,vehicleNo etc). I want to get all users who have a two-wheeler(type==two-wheeler). Is this possible with a firestore single query? How can I get those documents?
It's not possible. A query can consider only the documents within a single collection at a time. It can't reach into subcollections. What you will have to do is either copy the required data from the subcollection in the main collection that you need for the query, or compose a whole new collection that you can query. Duplicating data like this is common for NoSQL type databases like Firestore.

Can we query a firebase snapshot?

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

mongodb - keeping track of aggregated documents

I have a mongodb collection that stores raw information coming from an app. I wrote a multi-pipeline aggregation method to generate more meaningful data from the raw documents.
Using the $out operator in my aggregation function I store the aggregation results in another collection.
I would like to be able to either delete raw documents that were already aggregated, or somehow mark those documents so I know not to aggregate again.
I am worried that I cannot guaranty I won't miss out some documents that are created in between or create duplicate aggregated documents.
Is there a way to achieve this?