I have attached a picture, wherein i wish to rename the node during the run time for an application.
Short Answer:
Currently, Firebase doesn't allow you to rename a node/branch. So you might delete that node and create a new node again.
There is no api within Firebase for doing that. What can you do instead is to copy the information to another node and then simply delete the old one.
This is not a good practice to have the name of the product as a Firebase key. You need instead of using the product name, to use a unique identifier, an id. The best option is to use the unique key generated by the push() method. The name of the product will be then a child of your productId. Your database should look like this:
Firebase-root
|
--- prducts_details
|
--- -Ki-k6fM5GTRpQhGBRFRa
| |
| --- productName: "product1"
|
--- -Ki-oAAtTG1bWzLvKD5L
|
--- productName: "product2"
You have an option to Export the data. Once exported open and edit the exported.json. Here you can edit the node you want then save it and have Import to firebase db.
Related
I am using Cloud Firestore to make my own E-commerce App. I want my category collection to contain many categories like shoes, clothes, watches, etc and in each of those categories there are different products so I can click on that category and show all the related products on my app, please guide me or if you have another way to do this, please show me.
Category and Products
According to your comment:
just tens, this is just my personal project.
Since you only have tens of category names, then the best option that you have is to store them in a single document, in an array type field. Then each product document should contain a field where you have to specify the category. Your schema should look like this:
Firestore-root
|
--- shop (collection)
| |
| --- category (document)
| |
| --- names: ["shoes", "clothes", "watches"]
|
--- products (collection)
|
--- $productId (document)
|
--- name: "Nike Air Jordan"
|
--- category: "shoes"
To be able to display the category names, you should simply read the array that exists in the document, and display the content into a ListView, or even better, in a RecyclerView.
Furthermore, if you need to click on a particular category, and go forward to display only the products that correspond to a specific category, then you should use the following query:
FirebaseFirestore db = FirebaseFirestore.getInstance();
Query queryByCategory = db.collection("products").whereEqualTo("category", "shoes");
For displaying the products you might consider reading my answer from the following post:
How to display data from Firestore in a RecyclerView with Android?
The following article might also help you read the data with the use of the Firebase-UI library:
How to read data from Cloud Firestore using get()?
I have a list of numbers inside that have certain data, in which I am adding a value "Sí" or "No", as in this image:
The last "Sí" that I added was the one that is in number 4, but if I do a filter in Firebase with
.equalTo("Sí").limitToLast(1)
I return the value of "Sí" positioned in the number 5 and not in the 4 that was the last "Sí" that I added to the database. There is some way to recognize the last "Sí", without the need of that is in the last position of the list?
I still can not find the solution to this, I hope you can help me.
Thank you.
There is some way to recognize the last "Sí", without the need of that is in the last position of the list?
Yes there is. The most common approach would be to add under each object a new property of type Timestamp named lastUpdate and then query descending according to it. Everytime you update a value, change the value also to lastUpdate with the current timestamp. This is how your schema might look like:
Firebase-root
|
--- Users
|
--- 1
| |
| --- Activo: "Si"
| |
| --- lastUpdate: 1561202277
|
--- 2
|
--- Activo: "No"
|
--- lastUpdate: 1561202299
This is how to save the timestamp:
How to save the current date/time when I add new value to Firebase Realtime Database
And this is how to order descending:
Firebase Data Desc Sorting in Android
How to arrange firebase database data in ascending or descending order?
I have a problem with my job when I want to make a query with 2 context variables. I attached photos with my job and my components and when I run the job, it's giving me this error:
Exception in component tMysqlInput_1 (facebook_amazon_us)
java.lang.NullPointerException
at mava.facebook_amazon_us_0_1.facebook_amazon_us.tWaitForFile_1Process(facebook_amazon_us.java:2058)
at mava.facebook_amazon_us_0_1.facebook_amazon_us.tMysqlConnection_1Process(facebook_amazon_us.java:798)
at mava.facebook_amazon_us_0_1.facebook_amazon_us.runJobInTOS(facebook_amazon_us.java:5363)
at mava.facebook_amazon_us_0_1.facebook_amazon_us.main(facebook_amazon_us.java:5085)
What I want to do in this job: I have a csv file with multiple columns. The first one is called Reporting_Starts. I want to get the first registration from that column and put it in the query for a select like:
SELECT * FROM my_table WHERE MONTH(my_table.Reporting_Starts)='"+context.month+"'.
I cannot get why my tJava_4 sees the variables and tMysqlInput don't.
In my tJava_4 I have the following code:
System.out.println(context.month);[My job][1][after running the job][1][tJava_3][1][tJavaRow_1][1][tMysqlInput_1 query][1]
Please let me know if you need any additional information about the job.
Thanks!
With all the iterate links you have, I'm guessing the code isn't executing in the order you expect. Could you please make the following changes:
Remove all the iterate links from tFileList_1
Reorganize your jobs as :
tMysqlConnection_1
|
OnSubjobOk
|
tWaitForFile_1
|
Iterate
|
tFileList_1 -- Iterate -- tJava_3
|
OnSubjobOk
|
tFileInputDelimited_1 -- Main -- tJavaRow_1
|
OnSubjobOk
|
tMysqlInput -- tMap -- tMysqlOutput (delete mode, set a column as delete key)
|
tFileInputDelimited -- tMap -- tMysqlOutput (insert csv)
|
OnSubjobOk
|
tFileCopy
First test with just this part. Then if it works, you can add the rest of your job.
I have the following database structure:
Firestore-root
|
--- users (collection)
| |
| --- userId (document)
| |
| --- //user details
|
--- products (collection)
|
--- listId (document)
|
--- listProducts (collection)
|
--- productId
|
--- //product details
And I use the following code to delete the documents:
rootRef.collection("users").document(userId).delete(); //works fine
rootRef.collection("products").document(listId).delete();
The first line of code works perfectly but the second is not deleting the list document. Is it because it has a subcollection beneath it or am I doing something wrong?
How to delete the entire listId document together with everything it has beneath it?
Thanks!
Collections that are nested under a document, are not automatically deleted when you delete that document. When you only delete the document itself, the Firebase console will show the document ID in italic. The document itself isn't there anymore (you can see this when you select it, as it won't have any fields), but the nested collections are still accessible.
So I suspect that the products document is gone, but the nested collections still exist. As the Firestore documentation on deleting collection describes, you'll need to delete the documents from the collection to get rid of it.
Is it possible index a complete database without mentioning the table names explicitly in the data-config.xml as new tables are added everyday and I cannot change the data-config.xml everyday to add new tables.
Haven table names based on the date smells like there is something wrong in your Design. But given this requirement in your question you can add Data to your solr server without telling you have a DB. You just have to make sure you hav a unique ID for the data record in you solr Server with whom you can identify the corresponding record in your DB, something like abcd_2011_03_19.uniqueid. You can post the data to solr in Java in solrj or just plain xml or json.
Example:
--------------
| User Input |
--------------
|post
V
-----------------------------------
| My Backend (generate unique id) |
-----------------------------------
|post(sql) |post (e.g. solrj)
V V
------ --------
| DB | | solr |
------ --------
My ascii skillz are mad :D