1
votes

When I try the following code given on firebase documentation

doc_ref = db.collection(u'users')

def on_snapshot(doc_snapshot, changes, read_time):
    for change in changes:
        print(u'new doc:{}'.format(change.document.id))

doc_watch = doc_ref.on_snapshot(on_snapshot)

It prints all the entries even if they already existed before I invoked the listener. I only want to listen to the changes that take place after the listener is invoked and ignore any entries that already exited before I invoked the listener.

Example : if i had 3 documents in my users collection : user1, user2 and user3 already. I run my program and add another document - user4. I my program to print user4 and not user1, user2 or user3.

1

1 Answers

0
votes

The SDK doesn't provide a way to query for "everything that doesn't already exist". You should come up with your own query that satisfies what you want. In your case, perhaps you need a timestamp in each on of the documents that indicates when the document was created, and query for only documents with a creation date greater than the current time.