Is it possible to create a document template in Firestore? [duplicate] - firebase

This question already has answers here:
Firestore Documents Template [duplicate]
(1 answer)
Firebase Firestore: Is there a way to enforce required fields for all documents in a collection?
(3 answers)
Closed 7 months ago.
I need to add many documents to my firestore database and they all need the exact same fields. Is it possible to create a "template" so I don't need to keep adding the same fields to each document I make?

There is no concept of a document template in Firestore. If you need this, most devs create a simple administrative app, and you could of course also consider using one of the 3rd party content management systems that support Firestore.

Related

Firestore paginate documents for quiz app

I am building a quiz app and I am struggling about data structure in firebase.
Actually, I have two collections:
Questions collection, containing one document foreach question
Users Answers collection, containing one document foreach user. Inside user's document, there is one map per answered question where I store if question has been answered and if question has been right answered.
So, where is the problem ? For my app, I need two things:
Fetch list of a specific user answers. Actually there is no problem because I can query users answers collection for a specific user and retrieve all his answers within a single document.
Fetch list of a questions never answered by user. This is a quiz app, so it is mandatory to show questions never answered by user to progress in the game.
The current (not best) solution is this : when the user launch the app, I request all questions, get his answers and then I can know which question I should show to user and the ones I shouldn't. The problem of this solution is that I have to query all the questions documents so it represents a large number of reads (and firebase bill by number of reads 🙃).
I would like to paginate the number of questions to show to user (so questions never answered) to avoid extra-billing but I can't figure how to request them.
I tried to use not-in clause but it is limited to 10 items and I have a lot more than 10 questions.
I would like to know if you have any ideas to bypass this problem. Hope I'm clear enough.
Firestore doesn't support using the results of a query to exclude documents from another query. There are no SQL-like joins that query across documents in multiple collections.
If the provided inequality filter (10 items max) isn't sufficient for your use case, I'm afraid you're stuck with the solution you have now by filtering the results in the client app.
Some developers might choose to duplicate data into a SQL database to make these kinds of queries possible, but you'll have to decide for yourself if that's worthwhile.
We can consider this, I am wondering this could make your idea work.
This will only work when the users you know are constant.
Every questions docs need to have this property: not_answered_by
And set all users' ids list inside this property initially for all questions.
Once a user answered against one question then update certain question doc to remove that user id from not_answered_by So like this below, I remove user who has id:ccccc inside not_answered_by list from question :PXxzLaZp4kDSzewo7kht when user answered on that question.
Then you can run this query .where("not_answered_by", "array-contains", user_id) against questions collection to get all questions not answered by selected user.
If you have this structure of questions collection, then the powerful advantage is that you don't have to query double to get questions not answered by user, which does cost time and money. The remove action from not_answered_by doesn't affect speed low because you know which user id to be removed from which question id.
One tip: if you dont want to set not_answered_by to have all users' id list initially then just have another property: is_answer_started to set false for all questions. And whenever question is started to be answered then set not_answered_by to have all users' list.
not_answered_by is array of strings and it doesn't affect to your cost of firebase, important fact on your side is getting result in cheap and fast right?
Important to note: this is case of users' id list are constant, this doesn't work if users collection is dynamic which means user is added dynamically so please think this is a tricky method but I think it is best approach for now. PS: Firebase query doesn't support array_not_contains which I was about to find and use it. We can approach this in javascript via array includes function you know. :)
Vice versa, you can have answerd_by property inside question doc to get answered questions list against user.

Is there a way to run saved bigquery in RStudio directly using the link? [duplicate]

This question already has an answer here:
How to access “Saved Queries” programmatically?
(1 answer)
Closed 3 years ago.
I have a query saved on BigQuery and I wish to find a way to run it directly on RStudio without copy-pasting it. Is there a way where I can use the link of the saved query to tun it in RStudio?
For now, Saved queries is only accessible through BigQuery UI. There is no way to access it by any API or by code. You can follow feature request at issuetracker https://issuetracker.google.com/issues/111961970
Hope it helps.

Prevent duplicate entry in firebase database [duplicate]

This question already has answers here:
How do you prevent duplicate user properties in Firebase?
(2 answers)
Closed 3 years ago.
I want to add rule so that no duplicate rdate is added in database.
I am beginner to firebase and i don't know how to create rules for stopping duplicate.
This isn't possible with security rules, because rules don't have a way of performing queries for other nodes. The only way you can access other nodes in the database is using val() at the specific location you're interested in knowing about, but you have to know the full path to that specific location.
Your alternative is to make a request through a backend you control (such as Cloud Functions), and have that backend perform the query to check if there is a conflict.

Text search on firestore document field [duplicate]

This question already has answers here:
Firestore Comparison Operators - contains, does not contain, starts with
(2 answers)
Closed 4 years ago.
I am using cloud firestore as my database for my angular application. I wanted to implement text based search but the only option I see is using Angolia but I don’t want to use a 3rd party service. Is it possible to implement text search with just the functionality provided by firestore. Even if it returns the object by matching the first characters will work for me it does not have to be a “contain” query.
Firestore does not support full text search in any form. That's why the documentation suggests the use of another service.

Does Firebase storage offer unique Id's for files? [duplicate]

This question already has answers here:
Store files with unique/random names
(5 answers)
Closed 6 years ago.
So the realtime database offers me a direct way to reference a node by using its ID. Until now though, I have only seen examples of Firebase storage using the filename to create a reference. What if two files have the same name though? Must I prevent the user from uploading duplicate filenames? The URL is unique but as far as I know you aren't able to create a reference to the file based on it. Is there something I'm missing because this doesn't seem right to me. Thanks for your help.
In Firebase Storage it is up to you to determine the file name when uploading the file. There is no built-in method to generate a unique filename for Firebase Storage (like the push() method in the database).
If you have two references to the same path, they will be referring to the same file in Firebase Storage.
If you want globally unique filenames, you'll have to generate those yourself. One way would be to use the Firebase Database's push() method, but you can also use any other GUID-generator for your platform of choice.

Resources