Atakan Yıldırım
Atakan Yıldırım

Reputation: 892

Firestore getting or adding spesific data

I'm currently using Realtime Database, but I can't find any solution for my question.

My Inventory hierarchy in Realtime Database:

db data

My setValue function: (realtime database)

dbRef.child("inventoryData/inventory/" + gainedItem.getDbId() + "/items/" + gainedItem.getItemId()).setValue(dbInventoryItemClass);

How can I do this in Firestore?

In Firestore, I'm storing my data in a document. But when I want to edit spesific data, I have to download all document - edit - upload again. What I want is that I just want to edit specific data like in Realtime Database.

enter image description here

For example, I want to remove "0" from subList, in realtime database I can remove with:

dbRef.child("inventoryData/inventory/" + gainedItem.getDbId() + "/items/" + gainedItem.getItemId()).setValue(null);

How can I do this in firestore? I can't use this code: ref.collection("users").document(*userId*+"/inventory/0/items/2....").delete();

Is there any way like I used in Firebase?

Upvotes: 1

Views: 98

Answers (1)

EZH
EZH

Reputation: 73

I'm not entirly familier with what you want to gain, but I'll give it a try. with a single collection lets call it "ITEMS".

the "ITEMS" collection will hold the dbInventoryItemClass, and because we are using the firestore and not the realtime database, document read is the same regardless of the quantity of data in it (up to a certain limint) add in dbInventoryItemClass fields like inventoryID (that you can query with .whereEqualTo("inventoryID",0) to get all items in inventory 0. you can of course add as may identifications and chain several whereEqualTo's, just make sure to log the exeption given in the OnFailureListiner to get the link to create the index for the chained whereEqualTo query.

as for your question:

As I undestand it, I have to download all inventoryData in Firestore. Is it true?

as far as i know, in firebase firestore when you Query document(s), you'll get ONLY the document you queried (and not any subcollection assosiated with the document)

good luck!

Upvotes: 1

Related Questions