# Array

An `Array` is used to contain zero or more other values (representable using fields) in the form of a numerically indexed list.

#### Import

`from marrow.mongo.field import Array`

#### Inherits

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

## Attributes

This field type inherits all [`Field` attributes](https://github.com/marrow/mongo/tree/128b1ec81ec6a48e05a95c32b636deede377854b/reference/field/field.md#attributes). 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

## Usage

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.

## Examples

### Arrays of Scalar Values

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.

```python
class Record(Document):
    tags = Array(String(), assign=True)
    actors = Array(Reference('Account'))
```

### Array of Embedded Documents

Another principal pattern is that of an array of embedded documents, for example, an invoice with line items.

```python
class Invoice(Document):
    class Item(Document):
        ...

    items = Array(Embed(Item), assign=True)
```

## See Also

* [`Embed`](broken://pages/-LRHtsza3puSnTgfZoua)
* [`Reference`](broken://pages/-LRHtszlirbWWU4fsdBC)


---

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