# 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`.

Default`None`

#### `required`

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

Default`False`

#### `nullable`

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

Default`False`

#### `exclusive`

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

Default`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.

Default`FieldTransform()`

#### `validator`

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

Default`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.

Default`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.

Default`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`.*

Default`True`

#### `project`

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

Default`None`

#### `read`

Permission to read values from this field.

*Not internally enforced.*

Default`True`

#### `write`

Permission to assign values to this field.

*Not internally enforced.*

Default`True`

#### `sort`

Allow sorting/ordering on this field.

*Not internally enforced.*

Default`True`

## 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.

Type`set`

#### `__disallowed_operators__`

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

Type`set`

#### `__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](https://docs.mongodb.com/manual/reference/operator/query/type/#available-types).

Type`str`

## Usage

## Examples


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mongo.webcore.io/reference/field.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
