Changing Field Names In Firebase - firebase

Somehow in my firebase account 2 sets of data have changed the fieldname for 'DeviceID' to 'PeripheralID' and 'DeviceUUID'. Is there a way that I can search these and change them to be 'DeviceID'? I would prefer to do this by command line but will do whatever is easier.
Im thinking something along the line of firebase update:database ?

To answer the question with comments under question:
There is no tool for it. You'll have to download the data from database, edit JSON with some kind of text editor and upload it back to database.
This operation OVERRIDES information in database with information in JSON. In other words: uploading JSON changes database.
If you're using firebase console and data you want to change is not in whole database, you could open certain tree level and do those operation just there.

Related

Track of structure changes in a Progress database

I am asked to automate the tracking of changes in the structure of the database: Any modification, addition or removal of tables, fields, indexes, etc.
I have searched the audit but only found that it can track changes in the "Database schema", which is something else.
Do you know if it is possible to do that?
We use 11.6.3.
One wonders how those magical changes in the schema (I think you clarified that it was actually schema changes you wanted to automate) occur. Optionally it could be up to those making the changes to also keep track of them. Usually (hopefully) the database is updated using "delta df-files". Those df-files if kept are a changelog of the database.
Another option is to daily/hourly/weekly dump the data definitions:
CREATE ALIAS DICTDB FOR DATABASE sports.
DISPLAY LDBNAME("DICTDB").
RUN prodict/dump_df.p ("ALL",
"c:/temp/sports.df",
"").
DELETE ALIAS DICTDB. /* Optional */
Taken from this entry in the knowledge base: https://community.progress.com/s/article/15884
Then you can diff that df-file using your favorite tool or keep as it is.
If you actually mean structure (that's more how the data is stored in different files on disc) you can use the prostrct command to save a new st-file to disc:
prostrct list sports
This will save a file called sports.st. Handle it as above and you will have a changelog of the database structure.

Replace all the URL references to a file when it's replaced with another file in Firebase - Flutter mobile apps

I am building a mobile app using Flutter and have several collections in my Firebase Database, such as userData, posts, chats, etc.
I refer to user's profile picture URL (which is stored in Firebase Storage) in the posts collection as well. If a user changes their profile picture, the URL is only directly updated in the userData collection. Is there an easy way to update the URL in the posts collection (and all the other collections that the URL is referred to) without let's say looping through all the posts and updating the URL wherever it's found?
Thanks for the help in advance!
without let's say looping through all the posts and updating the URL wherever it's found?
No, that's precisely what you're going to have to do, except you don't have to read all the documents. Just query for the ones that match what you need to change. Firestore doesn't have a "update where" type of query that can update multiple documents in a single operation.
One way to do it is saving the photo url only in the users collection like you do, then in the others collections you save the uid of the user instead of his photo url, finally, in the client side, you query the user data based on the uid, in this way you only need to save and update the photo url in one collection

How do I create a Firebase collection?

So I am writing a chat application that I want to have multiple rooms, however, I can't find a button on the Firebase console that I can add child collections.
I've tried exporting, editing, then importing but that doesn't seem to do much. I have looked at some Firebase tutorial's but I can't find one that explains this.
Anything you enter in the console has to have a value itself, or at least one child (with a value). This is because Firebase does not explicitly store "null" or empty values in the database. You can enter the name of the collection and then rather than a value use the + button at the right to start adding children to it and so on until you reach a node with a value:
You cannot however simply create a placeholder for a collection that has no values. If you need a collection but can't initialize any of its data, just use your security rules to define what's allowed and write your client code knowing it may or may not exist. Firebase allows you to attach listeners to nodes that don't exist yet.

How can I querying a key value without retriving all data in Firebase?

I'm learning angularjs, firebase, angularfire by building a sample app. It's a dictionary app that any one can add a word, add several explanation to the word, add several common usage to the word, add example centences to the word. People can freely add new word via this web app. OR people can freely realtime search a word and display the content of that word. When I build the app.
I found everytime when I search a word, I have to load all the data and then check if the query string exist in the data and then display the content if exist. So, it's quite heavy if the library become very big.
How can I query a string if it exist from the server side and if exist, just download that piece of data?
Here is a very simple example that is on the firebase site (Retreiving data). I suggest you take a look at that page, there is a lot more info there about this subject. Now the example:
var ref = new Firebase("https://dinosaur-facts.firebaseio.com/dinosaurs");
ref.orderByChild([the child node to compare to]).equalTo([what you are searching]).on("child_added", function(snapshot) {
//do something with the data in snapshot
});

Photos and Database

I am working on a website, where user can upload photos of product they want to advertise.
I am saving photos in a folder on the web. In the table where I keep reference of photos, there is a key field photoid which is Identity field(primary key).
My repository has following methods
Photo photo = rep.NewPhoto();
photo.Title="Some Title";
rep.InsertPhoto(photo);
rep.SaveAll();
rep.SavePhoto(photo,uploadedPhoto);
rep.SaveAll();
I am using Linq to SQL for my data model.
Now my problem is, if I want to save my files
with a name which is coming from photoid, I have to Call the rep.SaveAll()
method to get the new created photoid and then save the photo with new id
and then I have to Call SaveAll() method to update it again with the changes
happend in SavePhoto() method.
Other option is I save the file with some random file number first and then Save the photo record in one step.
This is second approach.
Photo photo = rep.NewPhoto();
photo.Title="Some Title";
string filename = rep.SavePhoto(uploadedPhoto);
photo.FileName=filename;
rep.InsertPhoto(photo);
rep.SaveAll();
Saving files with photoid has one good point, photos can be easily loaded using its id.
What is a good approach to achieve this kind of functionality.
Help will be appritiate.
Cheers
Parminder
Second approach is definitely more efficient; other option could be to create a unique in your application layer(you can use guids ) and then use this as key DB record and same as file name.
If you are using the latest SQL Server, you might want to look into the new FILESTREAM field type:
http://technet.microsoft.com/en-us/library/bb933993.aspx
It's for exactly this kind of thing -- trying to get large blobs out of the table structure and onto the filesystem.
Other than that, I think you have the right idea with either way you go -- if you need two saves, you might want to consider a transaction if you care about what happens if the second save or SavePhoto fails.
A couple of things:
1) Consider storing the photos as VARBINARY(MAX) in the database. It will be much easier for people to manage as far as backups and restores go, and it's better for your database's integrity.
2) Consider using the partial methods of your L2SQL Photo class in order to achieve what you want. You should be able to change your Photo class's Update method to save your photo as well. Hope this helps.

Resources