# Class: Document

## Document

Document

## Constructor

#### new Document()

Creates a new Document instance. Documents allow you to create individual objects that can have standard ForerunnerDB CRUD operations run against them, as well as data-binding if the AutoBind module is included in your project.

Source:
  - Document.js, line 13

### Methods

- (static) db(dbopt) → {*}
- (static) drop() → {boolean}
- (static) find(query, optionsopt) → {Object}
- (static) isLinked() → {Boolean}
- (static) link(outputTargetSelector, templateSelector, optionsopt)
- (static) name(valopt) → {*}
- (static) setData(data, options) → {Document}
- (static) state(valopt) → {*}
- (static) unlink(outputTargetSelector, templateSelector)
- (static) update(query, update, optionsopt) → {Array}

#### (static) db(dbopt) → {*}

Gets / sets the db instance this class instance belongs to.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`db` | Db | <optional> | The db instance.

Source:
  - Document.js, line 55

##### Returns:

Type
  *

#### (static) drop() → {boolean}

Drops the document.

Source:
  - Document.js, line 449

##### Returns:

True if successful, false if not.

Type
  boolean

#### (static) find(query, optionsopt) → {Object}

Gets the document's data returned as a single object.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`query` | Object |  | The query object - currently unused, just provide a blank object e.g. {}
`options` | Object | <optional> | An options object.

Source:
  - Document.js, line 127

##### Returns:

The document's data object.

Type
  Object

#### (static) isLinked() → {Boolean}

Checks if the instance is data-bound to any DOM elements.

Source:
  - AutoBind.js, line 712

##### Returns:

True if linked, false if not.

Type
  Boolean

#### (static) link(outputTargetSelector, templateSelector, optionsopt)

Creates a link to the DOM between the document data and the elements in the passed output selector. When new elements are needed or changes occur the passed templateSelector is used to get the template that is output to the DOM.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`outputTargetSelector` |  |  |
`templateSelector` |  |  |
`options` | Object | <optional> | An options object.

Source:
  - AutoBind.js, line 722
See:
  - unlink

#### (static) name(valopt) → {*}

Gets / sets the document name.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`val` | String | <optional> | The name to assign

Source:
  - Document.js, line 64

##### Returns:

Type
  *

#### (static) setData(data, options) → {Document}

Sets the data for the document.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` |  |
`options` |  |

Source:
  - Document.js, line 73

##### Returns:

Type
  Document

#### (static) state(valopt) → {*}

Gets / sets the current state.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`val` | String | <optional> | The name of the state to set.

Source:
  - Document.js, line 46

##### Returns:

Type
  *

#### (static) unlink(outputTargetSelector, templateSelector)

Removes a link to the DOM between the document data and the elements in the passed output selector that was created using the link() method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`outputTargetSelector` |  |
`templateSelector` |  |

Source:
  - AutoBind.js, line 842
See:
  - link

#### (static) update(query, update, optionsopt) → {Array}

Modifies the document. This will update the document with the data held in 'update'.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`query` | Object |  | The query that must be matched for a document to be operated on.
`update` | Object |  | The object containing updated key/values. Any keys that match keys on the existing document will be overwritten with this data. Any keys that do not currently exist on the document will be added to the document.
`options` | Object | <optional> | An options object.

Source:
  - Document.js, line 217

##### Returns:

The items that were updated.

Type
  Array