Array
Last updated
Was this helpful?
Last updated
Was this helpful?
An Array
is used to contain zero or more other values (representable using fields) in the form of a numerically indexed list.
from marrow.mongo.field import Array
marrow.mongo:
Field
This field type inherits all . As a complex type, the first positional argument is always the nested field instance, other positional ordering is unaffected.
kind
A Field
subclass instance, or an instance of Field
itself if the type is dynamic.
Required
Instantiate and assign an instance of this class during construction of a new Document
subclass, passing another Field
instance representing the type to embed as the first positional parameter. Accessing as a class attribute will return a Queryable allowing array-like filtering operations, and access as an instance attribute will return a list
subclass containing cast values.
To reduce boilerplate when costructing new document instances utilizing Array
fields, if the assign
attribute is truthy and no default is otherwise assigned, an empty list will be assumed and assigned, eliminating the need for armour against None or non-existant conditions.
Tags are a very, very common storage pattern, modelled here using an Array
of free-form String
values. Foreign references are also common, though MongoDB itself provides no referential integrity validation.
Another principal pattern is that of an array of embedded documents, for example, an invoice with line items.
Embed
Reference