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.

None

required

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

False

nullable

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

False

exclusive

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

None

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.

FieldTransform()

validator

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

Validator()

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.

False

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.

True

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.

True

project

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

None

read

Permission to read values from this field.

Not internally enforced.

True

write

Permission to assign values to this field.

Not internally enforced.

True

sort

Allow sorting/ordering on this field.

Not internally enforced.

True

Metadata

Class-level metadata attributes meant for use when subclassing.

__name__

The database-side name of this field instance.

__allowed_operators__

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

set

__disallowed_operators__

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

set

__document__

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

__foreign__

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

str

Usage

Examples

results matching ""

    No results matching ""