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 1 year ago.
Improve this question
I am developing an app that the users can upload and vote for TagImages, so what is needed is to when someone check into a TagTopic get the most popular images and the newest one, so to do this ranking operation.
How should I approach this?
I think what you need is to use Firestore or Realtime, but in you case realtime would be better because the number of reads and writes, however, what you could do is to create an object for each image that contains the metadata about it like the number of votes, may be also down votes, who upload it, upload time, tags, or any things else you want. Then in you app or website you'll make a query that reads lets say top 5, and get them, then use the images names to get them from the cloud storage. For example:
images:{
image1Name:{
upvote: 10;
downvote: 2;
totolvote: 8;
uploader: 'Remoo';
uploadTime: '10:00:00AM 23/11/2021' //whatever the structure
}
}
Then you query them (this is Flutter example):
_firebaseDatabase
.reference()
.child("images")
.orderByChild('totolvote')
.limitToFirst(5)
.once().then(()=>{...})
Then get image1Name from cloud storage.
But note you can only use one orderByChild with each query, on the other hand you can use multiple where in Firestore, but there will be more cost on the reads and writes. Eventually it up to you and how you structure it. Hope this work for you.
Related
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 last year.
Improve this question
In Cloud Firestore, I want to add a collection like for ex. A,B,C and ..... within document I want to add two things(fields) basically
a image, and
a URL
Since I am new to Firebase ...Can anyone help me with this problem
As suggested by Vinamra Jaiswal, you need to store the URL as a string in the Firestore, you can refer to "How to store multiple url in firestore using flutter" for an example.
As for the image you can refer to "firestore database add image to record", where you can see that it is wiser to store the images in the Cloud Storage and then download the URLs and store them in Firestore.
You can also refer to the "Upload image to Cloud Storage, save URI in Firestore" video to get more insight on how to do this.
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 1 year ago.
Improve this question
I want to get subscriptions of users.
I can get user one by one then get each user subscriptions.
But this will make many document reads.
i want to get subscriptions 10 by 10 sorted by newest.
is that possible?
Firestore path
we can get users one by one then get each user subscription but this will make many reads
It doesn't matter if you get the documents one by one, or all documents at once, you'll always pay the same price. What I mean is that if you perform a query that returns 5 documents, you'll have to pay 5 read operations. If you read each of those 5 documents, one by one, the same number of read operations you have to pay.
I want to get subscriptions 10 by 10 sorted by newest is that possible?
In that case, you have to perform a query. For that, I recommend you start with the official documentation.
Subcollections: Firestore query subcollections
Pagination: https://firebase.google.com/docs/firestore/query-data/query-cursors
Be aware that asking questions in this way lowers the chances of getting answers.
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 2 years ago.
Improve this question
I am building a social media app and currently, I am storing Usernames, Users, and Posts in Firestore. I am afraid that it will be expensive if there are lots of users(around 50,000). So I planned to store half of the data in Firestore and other half in Realtime Database. Now I am confused if should store the Posts or the Users in Realtime Database. In which database should I put the Posts (Realtime or Firestore)?
Better to stick with 1 source of truth. Between the two I would choose firestore.
There is a pretty good comparison between the two and their tradeoffs here. Do you care only about mobile or do you want your app to work on web and mobile? I'd go with firestore if that is the case.
https://firebase.google.com/docs/database/rtdb-vs-firestore
Also you mention you have Usernames, Users, and Posts in your database. You should be storing usernames in your "Users" collection so you would really only have two different collections for these "Users" and "Posts". Also between the two, you are likely going to have more posts than there are users.
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 3 years ago.
Improve this question
I have a game that is super simple, no animations or that kind of stuff, it is some sort of trivia game. I can, already, save user's max. score locally via sharedpreferences, what I want to do now, is to save max. scores in some kind of server all users' and display them, maybe, in one screen.
I am not asking here for code, I realize that would be hard without seeing my game's source code.
I need any advice here to which method to use for saving user's 'simlpe' data?
Should I use firebase to save all users' max. scores or using Google Play Games would be a better choice?
By the way, I don't want to interrupt user for email, google sign in or any other that kind of methods. User will only update their username and profile photo (if they choose to).
You can use firebase realtime database or firestore to save user data. You don't have to use authentication if you don't want Google sign in.
Check the following :
https://pub.dev/packages/cloud_firestore
https://pub.dev/packages/firebase_database
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 4 years ago.
Improve this question
I want to migrate the data which already exists in my firebase database: Add a new field to all children; manipulate an existing field (ie a -> a + 3).
Since there is no real frontend available to do that, I wonder how it could be done?
If there is no real front end then:
If the database is small and you are using the RTD then download the JSON and edit it
If the database is large since you have no front end you should do it with Functions
How to do it with Functions
You have to create a Functions project that will have an HTTP request trigger, once you access that url, then the trigger will query the data and for each result will create new data.
For doing this the simplest way to start is following this video. You have to do the same but instead of returning something to the browser with send, just end the Function with a code 200 (if it worked).
I would recommend creating an extra node for verification something like migration_march: false and then set it to true once the migration is completed. That way you can avoid unintentional re-migrations. There should be a validation for this once the trigger is started.
Doing a query on Functions is fairly the same as doing it in any other SDK this is the Functions docs.
You will probably need to know how to work with promises since your algorithm is gonna be: a query where for each value found set a new value in another place and then move forward to the new value, here is an illustrative video (couldn't find the original video)