Skip to content
Draft
55 changes: 47 additions & 8 deletions google/cloud/firestore_v1/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

"""Classes for representing collections for the Google Cloud Firestore API."""
import random
import warnings

import six

Expand Down Expand Up @@ -257,6 +256,11 @@ def order_by(self, field_path, **kwargs):
def limit(self, count):
"""Create a limited query with this collection as parent.

.. note::

`limit` and `limit_to_last` are mutually exclusive.
Setting `limit` will drop previously set `limit_to_last`.

See
:meth:`~google.cloud.firestore_v1.query.Query.limit` for
more information on this method.
Expand All @@ -272,6 +276,29 @@ def limit(self, count):
query = query_mod.Query(self)
return query.limit(count)

def limit_to_last(self, count):
"""Create a limited to last query with this collection as parent.

.. note::

`limit` and `limit_to_last` are mutually exclusive.
Setting `limit_to_last` will drop previously set `limit`.

See
:meth:`~google.cloud.firestore_v1.query.Query.limit_to_last`
for more information on this method.

Args:
count (int): Maximum number of documents to return that
match the query.

Returns:
:class:`~google.cloud.firestore_v1.query.Query`:
A limited to last query.
"""
query = query_mod.Query(self)
return query.limit_to_last(count)

def offset(self, num_to_skip):
"""Skip to an offset in a query with this collection as parent.

Expand Down Expand Up @@ -375,13 +402,25 @@ def end_at(self, document_fields):
return query.end_at(document_fields)

def get(self, transaction=None):
"""Deprecated alias for :meth:`stream`."""
warnings.warn(
"'Collection.get' is deprecated: please use 'Collection.stream' instead.",
DeprecationWarning,
stacklevel=2,
)
return self.stream(transaction=transaction)
"""Read the documents in this collection.

This sends a ``RunQuery`` RPC and returns a list of documents
returned in the stream of ``RunQueryResponse`` messages.

Args:
transaction
(Optional[:class:`~google.cloud.firestore_v1.transaction.Transaction`]):
An existing transaction that this query will run in.

If a ``transaction`` is used and it already has write operations
added, this method cannot be used (i.e. read-after-write is not
allowed).

Returns:
list: The documents in this collection that match the query.
"""
query = query_mod.Query(self)
return query.get(transaction=transaction)

def stream(self, transaction=None):
"""Read the documents in this collection.
Expand Down
Loading