Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 days ago.
Improve this question
I have subcollections in firestore database and I want to fetch data from subcollections using streambuilder also use Listview.builder to show.
I have database like this
- Collection ->doc1->collection->doc->data
->doc2->collection->doc->data
->doc3->collection->doc->data
->doc4->collection->doc->data
->doc5->collection->doc->data
->doc6->collection->doc->data
Please write a query to fetch the data from database like this
For Future call:
you could use something like, if you don't know the next value for the document.
For streambuilder:
Would be to much heavy for encapsulated querys to make it.
One way to get values from a "col>doc>col>doc>data" is to get it directly like:
Stream<UserData?>? get data {
if(uid != null)
return collectionsT.doc(uid).collection("col1").doc("doc2").snapshots().map(_dataFromSnapShot);
return null;
}
Replicating that data in a diferent shorter path collection.
Or saving the path in some kind of a "static" path Table> staticPath="doc/col/doc/col"
Normally "doc>col" structures are created in a way to have all the information that will be used in that screen that is designed to show, even if the information is replicated.
A trick is to calculate if the reads that will be done to that document with replicated information is lower than the updates. If that is the case, is needed a way to sync that information on the specific document. That is the information that google gives, by the video tutorials.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have this code, and it is supposed to write to Firestore. However, when it does the function, in the back end, it shows highlighted as red and then disappears.
db.collection("jokes").document("Dad Jokes").setData(["\(dadJokeNum + 1)": Joke.text!])
Please help.
Using SetData without Merge will delete existing values - it is suggested that if the document exists prior, you should always be using merge: true. Firestore also has a limited 1 write per second each, you should be managing writes together as it is most likely similar writes will conflict and potentially resolve out of order.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I'm transitioning from a SQLite implementation to CoreData.
In SQLite, searches are fairly limited. In a typical search, for a string like "card", I would want to know if any members of a set of letters like [n,l,j,x], would be a valid part of a word, or a whole word, in a stored dictionary of strings.
So, in the example above, I would have to look for "nard","lard","jard","xard" and then repeat that process for each subsequent position in the string: "cnrd","clrd","cjrd","cxrd".
This is slightly controlled by the fact that I only need a single match per position in the target string to "qualify" it, so I can search for "nard","cnrd","cand","carn", and if I get a match at any point, I can mark that point in the target word as qualified, and focus on the other targets.
Thus, if I got a match at "nard" and no other matches, the next loop might check "clrd","cald","carl", and so on. If I got matches at "nard","cand", the next loop would be "clrd","carl" : you get the idea.
Does CoreData, which I know under the hood is just SQLite anyway, offer any more advanced features that would allow me to improve the default algorithms I've used, perhaps using regex? Can a pattern like \^{3}[nljx]\ be somehow used?
I'm not at the point where I'm writing the code to experiment in this direction, so anything people can point me to is great.
When you use a SQLite store with Core Data, predicates are translated into SQLite code and executed in SQLite. Predicates therefore have SQLite's limits on what's possible. Core Data can use other store types with different capabilities and limitations-- for example, you can use a predicate that's any arbitrary block of code, but the entire persistent store gets loaded into memory all the time. Whether one of those would work for you depends on how much data you have.
Yes, you can use a predicate with NSMatchesPredicateOperatorType to do regex searching. SQLite doesn't support regexes directly, but Core Data registers a custom NSCoreDataMatches function to do the work without bringing everything into memory.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
The question is simple ( I want to count the collections inside the Firestore which are in the first row list) as shown in the pic below:
As you saw in the picture I have 3 collections in the list... so what about if I have a big list or as you know this list might has more and more collections in the future.
**So, Ho to get them counted programmatically? **
WHY ??
The answer is:
I want to use the count inside an array that will determine the number of cells inside the UICollectionView because I want to show the products of each collection in Firestore inside the Reusable cells
All methods which are in google search are talking about how to count the documents not about the main collection count !!
There is no API in the Firebase SDKs for iterating root collections or subcollections of a document, which means you have to know the name of the collection to perform any queries. Only in Node.js server SDK you can use the listCollections() to get the desired result.
As an alternate, you can make a separate collection allCollections and then whenever you create new root collection, add one document with same name in allCollections and then you can count from that new collection.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
What's the best practice for getting the last added element (let's say we know that because of a created_at field on the resource).
Should it be a call to the get all with max results on 1 like:
GET ../rest/v1/article?page=0&size=1&order=created_at,desc
and will return an array of one element
or maybe an "special" call like:
GET ../rest/v1/article/last
and will return an element.
I am looking for a best practice if there's one pattern for this.
Thanks!
I'm not a RESTful expert, but in my opinion the first solution seems the best.
The second is more practical, but routes are often associated with resources, the addition of a "last", especially preceded by a "/" seems strange to me.
In addition, API users usually use the sorting parameters, and what about users which need 10 last elements ?
If you add something after ../rest/v1/article, it must be an ID for one particular element, a sub-resource, or for actions that are outside the CRUD like ../rest/v1/article/:id/subscription.
Both URLs are RESTful and identify a Resource. Of course the first would return a collection containing a single element while the second would return this element directly.
The first form will be automatically supported if you support paging and sorting at all.
You write
or maybe an "special" call
I don't see this as an 'or', it should be an 'and'. The second form is optional and it could be helpful. If you have an URL pattern like
GET ../rest/v1/article/{id}
it is easy to implement logic that can distinguish normal IDs like, for example, 123 or A567 from special IDs like 'last`.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am looking for a simple example of State monad in a business application.
I have found good examples -- memoisation to calculate Fibonacci numbers and random numbers generation -- but I would like to see an example from a business domain (preferably in Scala).
For example, I can easily find examples of using Option, Either, List, Reader, and Writer monads:
option : look up an entity (order, product, customer, whatever) which does not exist
either : any failure
list : customer orders, order items, etc.
reader : read any entity from the database
writer : write to the log
Now I am looking for something similar for State monad, i.e. any stateful computation with a mutable state, as I understand it.
The typical application where I reach for State is where I need a supply of values, like a random number generator or a supply of unique identifiers.
Another typical use case is testing an application that interacts with a database. Using State, you can simulate an in-memory database and check that the program manipulates the database in the expected way.