Collections provide a quick and easy way to interact with many documents of the same type all at once. They also provide a mechanism for basic joins across one addition table (due to current limitations of RethinkDB and how it handles joins). Collections act like Lists of RethinkModel objects, but provide an interface to order the results, and optionally, eqJoin across one other table, along with filtering of results.

Initialize a new Collection

Optionally you can also pass a dictionary which will be used as a filter. For more information on how filters work, please see the RethinkDB docs

collection = RethinkCollection(gateModel)

Join on a table

collection.joinOn(episodeModel, "episodes")

Order the Results

collection.orderBy("episodes", "ASC")

Finally, Fetch the Results

result = collection.fetch()

Result acts like a List, containing all of the Documents which are part of the collection, all pre wrapped in a RethinkModel object.

rethinkCollection Module

class rethinkORM.rethinkCollection.RethinkCollection(model, filter=None)[source]

A way to fetch groupings of documents that meet a criteria and have them in an iterable storage object, with each document represented by RethinkModel objects

__init__(model, filter=None)[source]

Instantiates a new collection, using the given models table, and wrapping all documents with the given model.

Filter can be a dictionary or lambda, similar to the filters for the RethinkDB drivers filters.

joinOn(model, onIndex)[source]

Performs an eqJoin on with the given model. The resulting join will be accessible through the models name.

joinOnAs(model, onIndex, whatAs)[source]

Like joinOn but allows setting the joined results name to access it from.

Performs an eqJoin on with the given model. The resulting join will be accessible through the given name.

orderBy(field, direct='desc')[source]

Allows for the results to be ordered by a specific field. If given, direction can be set with passing an additional argument in the form of “asc” or “desc”


Fetches the query and then tries to wrap the data in the model, joining as needed, if applicable.

Table Of Contents

Previous topic


Next topic


This Page