Migrate existing Firebase data [closed] - firebase

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)

Related

Best method of back end pseudo user validation with DynammoDB [closed]

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 last month.
Improve this question
I have a simple app that is using a dynammoDB table with node/express as the back end. I let users add and then edit things. I am trying to determine the best way to verify that a user owns the item that they are editing/deleting.
Here is what i've looked at. Is there a better method?
1. User cognito ID is part of the item when created
2. User token is sent as part of edit
3. Item is pulled from table when edit starts
4. Token is decoded and the id is compared to the one pulled from the table
The obvious problem here is that every edit requires a read. This seems wrong.
Another method
1. User cognito ID is part of the item when created
2. User token is sent as part of edit
3. Original id is sent from the item as well
4. Token is decoded and the decoded id is compared to the one sent
This doesn't require a read, but would let a clever person edit things that they shouldn't.
Is there another way that I am missing? I don't want to create some separate IAM policy for each user.
You should use DynamoDBs fine grained access control that can dynamically allow Cognito users only read/edit their own data:
https://aws.amazon.com/blogs/aws/fine-grained-access-control-for-amazon-dynamodb/

How to create a table in firebase? (Previous title: How to create a database in firebase?) [closed]

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 5 months ago.
Improve this question
I want to test working with Firebase.
I want to use 'Firebase` in the application.
I created a project.
How to create a table in firebase??
Based on our comments below your question:
If you have followed what is explained in the Firebase documentation page I referred to in my comment and you get to the page shown in the screenshot in your question, then the next steps are the following:
Learn how to structure data for Realtime Database.
Start creating some data in the database
Learn how to secure your data
Read the data that is in your database
Read all the doc to understand all the possibilities offered by the Realtime Database service
Note #1: When coming from the SQL world, it is quite common to ask "How to create a table?".
There is actually no concept of table in the Realtime Database. If you read the doc about how to structure your database you'll find the following remark:
All Firebase Realtime Database data is stored as JSON objects. You can
think of the database as a cloud-hosted JSON tree. Unlike a SQL
database, there are no tables or records. When you add data to the
JSON tree, it becomes a node in the existing JSON structure with an
associated key.
Note #2: The links in points 2 and 4 above are about the JS SDK but you'll find in the documentation menu the corresponding documentation for other languages/SDKs (Android, iOS, etc...)
Note #3: The documentation lists a similar list of next steps.

Where do I the ranking functions for firebase Storage [closed]

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.

How to automatically remove data from firestore after a specific time? [closed]

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 2 years ago.
Improve this question
I am developing an app in flutter where I have a stories section. Where users can upload stories ( Text / Images). What I want is to automatically delete the posts after one day.
What I have achieved is to delete one day ago data by checking the timestamp of the post and a simple calculation and a remove call to delete it.
But what I want to achieve is an automated process. Like data is automatically deleted after one day without checking for posts on random calls or time. Like I don't know if it's possible or not. But if someone has a solution it would be a great favour. Thakns
Before displaying an item you can check if it is posted in the last 24 hours and if not then don't display it.
To delete the items from Firestore you can set a scheduled job in the backend.
You can use cloud functions pubsub. Write a function like "every one hour find & delete the items that are created before the last 24 hours". Take a look here Schedule functions.

How do you set up an API key system for your website? [closed]

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
Let say that I have a website with some information that could be access externally. Those information need to be only change by the respected client. Example: Google Analytic or WordPress API key. How can I create a system that work like that (no matter the programming language)?
A number of smart people are working on a standard, and it's called OAuth. It already has a number of sample implementations, so it's pretty easy to get started.
Simple:
Generate a key for each user
Deny access for each request without this key
Currently, I use a concatenation of multiple MD5s with a salt. The MD5s are generated off of various concatenations of user data.
A good way of generating a key would be to store a GUID (Globally Unique Identifier) on each user record n the database. GUID is going to be unique and almost impossible to guess.
There are also infrastructure services that manage all this for you like http://www.3scale.net (disclosure I work there), http://www.mashery.com and http://www.apigee.com/.

Resources