# Class: Collection

## Collection

Class representing a collection.

#### new Collection()

collection.js, line 10
  Note: Do not instantiate directly.

### Members

#### namestring

  The name of the collection.

### Methods

#### aggregate(pipeline){Cursor}

collection.js, line 59
  Evaluate an aggregation framework pipeline.

  Name | Type | Description
  --- | --- | ---
  `pipeline` | Array.<object> | The pipeline.

  ##### Returns:

  Type | Description
  --- | ---
  Cursor |

  ##### Example

      col.aggregate([
          { $match: { x: { $lt: 8 } } },
          { $group: { _id: '$x', array: { $push: '$y' } } },
          { $unwind: '$array' }
      ]);

#### find(expr, projection_spec){Cursor}

collection.js, line 37
  Open a cursor and optionally filter documents and apply a projection.

  Name | Type | Description
  --- | --- | ---
  `expr` | object | optional The query document to filter by.
  `projection_spec` | object | optional Specification for projection.

  ##### Returns:

  Type | Description
  --- | ---
  Cursor |

  ##### Example

      col.find({ x: 4, g: { $lt: 10 } }, { k: 0 });

#### insert(docs, cb){Promise}

collection.js, line 92

  Name | Type | Description
  --- | --- | ---
  `docs` | object | Array.<object> | Documents to insert.
  `cb` | function | optional The result callback.

  ##### Returns:

  Type | Description
  --- | ---
  Promise |

  ##### Examples

      col.insert([{ x: 4 }, { k: 8 }], (error) => {
          if (error) { throw error; }
      });

      col.insert({ x: 4 }, (error) => {
          if (error) { throw error; }
      });

#### remove(expr, cb){Promise}

collection.js, line 183
  Delete documents that match a filter.

  Name | Type | Description
  --- | --- | ---
  `expr` | object | The query document to filter by.
  `cb` | function | optional The result callback.

  ##### Returns:

  Type | Description
  --- | ---
  Promise |

  ##### Example

      col.remove({ x: { $ne: 10 } }, (error) => {
          if (error) { throw error; }
      });

#### update(expr, spec, cb){Promise}

collection.js, line 166
  Update documents that match a filter.

  Name | Type | Description
  --- | --- | ---
  `expr` | object | The query document to filter by.
  `spec` | object | Specification for updating.
  `cb` | function | optional The result callback.

  ##### Returns:

  Type | Description
  --- | ---
  Promise |

  ##### Example

      col.update({
          age: { $gte: 18 }
      }, {
          adult: true
      }, (error) => {
          if (error) { throw error; }
      });