Field

A Field represents a data types storable within MongoDB and the associated machinery for access, querying, and manipulation. It is the common base class for almost all field types and can be used standalone to represent a "dynamic" field.

Import

from marrow.mongo import Field

Inherits

marrow.schema:Attribute

Attributes

name

The database-side name of the field, stored internally as the metadata property __name__.

Default calculated when assigned as a class attribute from the name given to the Field instance during class construction.

default

The default value to utilize if the field is missing from the backing store. You may assign a callback routine returning a value to utilize instead.

choices

The permitted set of values as a sequence; may be static or a dynamic, argumentless callback routine as per default.

DefaultNone

required

Must have a value assigned. None, an empty string, and other falsy values are acceptable.

DefaultFalse

nullable

If True, will store None. If False, will store any non-None default, or remove the field from the backing store.

DefaultFalse

exclusive

The set of other fields that must not be set for this field to be writeable.

DefaultNone

Local Manipulation

Define how Python-side code interacts with the stored MongoDB data values.

transformer

A Marrow Schema Transformer class to use when loading or storing values.

DefaultFieldTransform()

validator

A Marrow Schema Validator class to use when validating values during assignment.

DefaultValidator()

assign

Automatically assign the default value to the backing store when constructing a new instance or the value is found to be missing on access.

DefaultFalse

Predicates

These are either argumentless callback routines returning, or simply the constant values:

  • None Interpreted as "no opinion", with the fallback being to deny or exclude.

  • False (or falsy) Explicitly forbid, deny, or exclude.

  • True (or truthy) Explicitly allow or include.

These are used to restrict or define security-like behaviours.

positional

Permit this field to be populated through positional assignment during instantiation of its containing class.

DefaultTrue

repr

Include this field in the programmers' representation, primarily utilized for REPL shells, logging, tracebacks, and other diagnostic purposes.

Protect sensitive fields from accidental exposure by assigning False.

DefaultTrue

project

Inlcude (or exclude) this field from the default projection.

DefaultNone

read

Permission to read values from this field.

Not internally enforced.

DefaultTrue

write

Permission to assign values to this field.

Not internally enforced.

DefaultTrue

sort

Allow sorting/ordering on this field.

Not internally enforced.

DefaultTrue

Metadata

Class-level metadata attributes meant for use when subclassing.

__name__

The database-side name of this field instance.

Read-Only

__allowed_operators__

The permissable MongoDB filter and update operators, or hash-prefixed groups of operations.

Typeset

__disallowed_operators__

Specific operations may be excluded from group-based inclusion, if utilized above.

Typeset

__document__

A weak reference to the document the instance is bound to; automatically popualted.

Read-Only

__foreign__

The MongoDB stored datatype, as defined by the $type operator.

Typestr

Usage

Examples

Last updated