Firestore hat:
Code: Select all
{
"doc1": {"downloadedBy": ["device12345","device2468"]}, // Downloaded by Device 1 and 3
"doc2": {"downloadedBy": ["device12345","device2468"]}, // Downloaded by Device 1 and 3
...
"doc101": {"downloadedBy": ["device2468"]}, // Downloaded by device 3
"doc102": {"downloadedBy": []}, // Newly added
}
Zweites Gerät (Gerät 67890): Die Dokumente doc1 bis doc102 sind enthalten, da sie nicht von Gerät 67890 heruntergeladen werden.
Drittes Gerät (Gerät 2468):Dokumente doc102 sind enthalten, da sie nicht von Gerät2468 heruntergeladen werden.
Angenommen, dies ist korrekt, bin ich mir nicht sicher, ob die Abfrage in dieser Situation so heruntergeladen werden würde.
Code: Select all
def on_snapshot(doc_snapshot, changes, read_time):
for change in changes:
if change.type.name == "ADDED":
print(f"New document added: {change.document.id}")
elif change.type.name == "MODIFIED":
print(f"Document modified: {change.document.id}")
elif change.type.name == "REMOVED":
print(f"Document removed: {change.document.id}")
device_id = "device12345" # Replace with your actual device ID
user_id = "your_user_id" # Replace with the actual user ID
# Reference the subcollection and attach the listener
query = db.collection("PAD").document(user_id).collection("Field").where("downloadedBy", "not-in", [device_id])
Code: Select all
Device 1 (device12345):
Initial Reads: 2documents.
Subsequent Reads: None if no new matching documents are added.
Total Reads = 2.
Device 2 (device67890):
Initial Reads: 102 documents.
Subsequent Reads: None if no new matching documents are added.
Total Reads = 102.
Device 3 (device2468):
Initial Reads: 1 document (doc102).
Subsequent Reads: None if no new matching documents are added.
Total Reads = 1.