# Boolean

Boolean fields store boolean values, as expected. It also provides convienence for accepting *truthy* or *falsy* values. See the usage section for more details.

### Import

`from marrow.mongo.field import Boolean`

### Inherits

`marrow.mongo:`**`Field`**

## Attributes

This field type inherits all [`Field` attributes](https://github.com/marrow/mongo/tree/128b1ec81ec6a48e05a95c32b636deede377854b/reference/field/field.md#attributes) and represents a singular, scalar boolean value. In addition to the storage and retrieval of pure `True` and `False` values, the field configuration defines allowable "truthy" values (to cast to `True`) and "falsy" values (to cast to `False`).

### `truthy`

Values to interpret as `True`, storing `True` if they are assigned.

Default`('true', 't', 'yes', 'y', 'on', '1', True)`

Added`>=1.1.3`

### `falsy`

Values to interpret as `False`, storing `False` if they are assigned.

Default`('false', 'f', 'no', 'n', 'off', '0', False)`

Added`>=1.1.3`

In versions prior to 1.1.3 the "truthy" and "falsy" values are hardcoded at the defaults presented above.

## Usage

Instantiate and assign an instance of this class during construction of a new `Document` subclass. Accessing as a class attribute will return a Queryable allowing filtering operations, and access as an instance attribute will return a `bool` cast value.

Assignment of any value matched by the `truthy` iterable (via `in` comparison) will store `True`, and likewise with the `falsy` iterable storing `False`. Additionally, if an attempt is made to assign a non-boolean, non-string value, the value will be passed through `bool()` conversion prior to storage, allowing use of objects which define their own `__nonzero__`/`__bool__` methods.


---

# 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/fields/boolean.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.
