File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -329,6 +329,51 @@ def get(self, token=None):
329
329
330
330
return docs
331
331
332
+ def list_of_documents (self , token = None ):
333
+ """ List all sub-documents of the current collection.
334
+
335
+ :type token: str
336
+ :param token: (Optional) Firebase Auth User ID Token, defaults
337
+ to :data:`None`.
338
+
339
+
340
+ :return: A list of document ID's.
341
+ :rtype: list
342
+ """
343
+
344
+ docs = []
345
+
346
+ path = self ._path .copy ()
347
+ self ._path .clear ()
348
+
349
+ if self ._credentials :
350
+ db_ref = _build_db (self .__datastore , path )
351
+
352
+ list_doc = list (db_ref .list_documents ())
353
+
354
+ for doc in list_doc :
355
+ docs .append (doc .id )
356
+
357
+ else :
358
+
359
+ req_ref = f"{ self ._base_url } /{ '/' .join (path )} ?key={ self ._api_key } "
360
+
361
+ if token :
362
+ headers = {"Authorization" : "Firebase " + token }
363
+ response = self ._requests .get (req_ref , headers = headers )
364
+
365
+ else :
366
+ response = self ._requests .get (req_ref )
367
+
368
+ raise_detailed_error (response )
369
+
370
+ if response .json ().get ('documents' ):
371
+ for doc in response .json ()['documents' ]:
372
+ doc_id = doc ['name' ].split ('/' )
373
+ docs .append (doc_id .pop ())
374
+
375
+ return docs
376
+
332
377
def limit_to_first (self , count ):
333
378
""" Create a limited query with this collection as parent.
334
379
You can’t perform that action at this time.
0 commit comments