mongo-portable
Version:
Portable Pure JS MongoDB - Based on Monglodb (https://github.com/euforic/monglodb.git) by Christian Sullivan (http://RogueSynaptics.com)
610 lines (373 loc) • 14.3 kB
Markdown
[Mongo Portable](../README.md) > [Collection](../classes/collection.md)
# Class: Collection
## Hierarchy
**Collection**
## Index
### Constructors
* [constructor](collection.md#constructor)
### Properties
* [databaseName](collection.md#databasename)
* [doc_indexes](collection.md#doc_indexes)
* [docs](collection.md#docs)
* [emit](collection.md#emit)
* [fullName](collection.md#fullname)
* [logger](collection.md#logger)
* [name](collection.md#name)
* [snapshots](collection.md#snapshots)
### Methods
* [aggregate](collection.md#aggregate)
* [backup](collection.md#backup)
* [backups](collection.md#backups)
* [bulkInsert](collection.md#bulkinsert)
* [clearBackups](collection.md#clearbackups)
* [delete](collection.md#delete)
* [destroy](collection.md#destroy)
* [drop](collection.md#drop)
* [ensureIndex](collection.md#ensureindex)
* [find](collection.md#find)
* [findOne](collection.md#findone)
* [insert](collection.md#insert)
* [remove](collection.md#remove)
* [removeBackup](collection.md#removebackup)
* [rename](collection.md#rename)
* [restore](collection.md#restore)
* [save](collection.md#save)
* [update](collection.md#update)
* [checkCollectionName](collection.md#checkcollectionname)
### Object literals
* [_noCreateModifiers](collection.md#_nocreatemodifiers)
---
## Constructors
<a id="constructor"></a>
### constructor
⊕ **new Collection**(db: *`any`*, collectionName: *`any`*): [Collection](collection.md)
*Defined in [collection/Collection.ts:71](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L71)*
**Parameters:**
| Param | Type | Description |
| ------ | ------ | ------ |
| db | `any` | Additional options |
| collectionName | `any` | The name of the collection |
**Returns:** [Collection](collection.md)
___
## Properties
<a id="databasename"></a>
### databaseName
**● databaseName**: *`any`*
*Defined in [collection/Collection.ts:62](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L62)*
___
<a id="doc_indexes"></a>
### doc_indexes
**● doc_indexes**: *`any`*
*Defined in [collection/Collection.ts:66](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L66)*
___
<a id="docs"></a>
### docs
**● docs**: *`any`*
*Defined in [collection/Collection.ts:64](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L64)*
___
<a id="emit"></a>
### emit
**● emit**: *`function`*
*Defined in [collection/Collection.ts:69](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L69)*
#### Type declaration
▸(name: *`string`*, args: *`object`*): `Promise`<`void`>
**Parameters:**
| Param | Type |
| ------ | ------ |
| name | `string` |
| args | `object` |
**Returns:** `Promise`<`void`>
___
<a id="fullname"></a>
### fullName
**● fullName**: *`any`*
*Defined in [collection/Collection.ts:63](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L63)*
___
<a id="logger"></a>
### `<Protected>` logger
**● logger**: *`JSWLogger`*
*Defined in [collection/Collection.ts:71](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L71)*
___
<a id="name"></a>
### name
**● name**: *`any`*
*Defined in [collection/Collection.ts:61](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L61)*
___
<a id="snapshots"></a>
### snapshots
**● snapshots**: *`any`*
*Defined in [collection/Collection.ts:67](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L67)*
___
## Methods
<a id="aggregate"></a>
### aggregate
▸ **aggregate**(pipeline: *`any`*, options?: *`object`*): `any`
*Defined in [collection/Collection.ts:1021](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L1021)*
Calculates aggregate values for the data in a collection
*__method__*: Collection#aggregate
**Parameters:**
| Param | Type | Default value | Description |
| ------ | ------ | ------ | ------ |
| pipeline | `any` | - | A sequence of data aggregation operations or stages |
| `Default value` options | `object` | { forceFetch: false } |
**Returns:** `any`
If "options.forceFetch" set to true returns the array of documents, otherwise returns a cursor
___
<a id="backup"></a>
### backup
▸ **backup**(backupID: *`any`*, callback?: *`any`*): `Promise`<`any`>
*Defined in [collection/Collection.ts:866](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L866)*
*__ignore__*:
**Parameters:**
| Param | Type |
| ------ | ------ |
| backupID | `any` |
| `Optional` callback | `any` |
**Returns:** `Promise`<`any`>
___
<a id="backups"></a>
### backups
▸ **backups**(): `any`[]
*Defined in [collection/Collection.ts:904](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L904)*
*__ignore__*:
**Returns:** `any`[]
___
<a id="bulkinsert"></a>
### bulkInsert
▸ **bulkInsert**(docs: *`any`*, options: *`any`*, callback?: *`any`*): `ThenPromise`<`Object`>
*Defined in [collection/Collection.ts:209](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L209)*
Inserts several documents into the collection
**Parameters:**
| Param | Type | Description |
| ------ | ------ | ------ |
| docs | `any` | Documents to be inserted |
| options | `any` |
| `Optional` callback | `any` |
**Returns:** `ThenPromise`<`Object`>
Returns a promise with the inserted documents
___
<a id="clearbackups"></a>
### clearBackups
▸ **clearBackups**(): `void`
*Defined in [collection/Collection.ts:949](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L949)*
**Returns:** `void`
___
<a id="delete"></a>
### delete
▸ **delete**(selection: *`any`*, options: *`any`*, callback?: *`any`*): `Promise`<`any`[]>
*Defined in [collection/Collection.ts:741](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L741)*
Alias for { Collection#remove}
*__method__*: Collection#delete
**Parameters:**
| Param | Type |
| ------ | ------ |
| selection | `any` |
| options | `any` |
| `Optional` callback | `any` |
**Returns:** `Promise`<`any`[]>
___
<a id="destroy"></a>
### destroy
▸ **destroy**(selection: *`any`*, options: *`any`*, callback?: *`any`*): `Promise`<`any`[]>
*Defined in [collection/Collection.ts:750](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L750)*
Alias for { Collection#remove}
*__method__*: Collection#destroy
**Parameters:**
| Param | Type |
| ------ | ------ |
| selection | `any` |
| options | `any` |
| `Optional` callback | `any` |
**Returns:** `Promise`<`any`[]>
___
<a id="drop"></a>
### drop
▸ **drop**(options: *`any`*, callback?: *`any`*): `Promise`<`any`[]>
*Defined in [collection/Collection.ts:768](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L768)*
Drops a collection
*__method__*: Collection#drop
**Parameters:**
| Param | Type |
| ------ | ------ |
| options | `any` |
| `Optional` callback | `any` |
**Returns:** `Promise`<`any`[]>
Promise with the deleted documents
___
<a id="ensureindex"></a>
### ensureIndex
▸ **ensureIndex**(): `void`
*Defined in [collection/Collection.ts:855](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L855)*
*__ignore__*:
**Returns:** `void`
___
<a id="find"></a>
### find
▸ **find**(selection: *`any`*, fields: *`any`*, options: *`any`*, callback?: *`any`*): `Promise`< `any`[] | [Cursor](cursor.md)>
*Defined in [collection/Collection.ts:263](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L263)*
Finds all matching documents
*__method__*: Collection#find
**Parameters:**
| Param | Type |
| ------ | ------ |
| selection | `any` |
| fields | `any` |
| options | `any` |
| `Optional` callback | `any` |
**Returns:** `Promise`< `any`[] | [Cursor](cursor.md)>
Returns a promise with the documents (or cursor if "options.forceFetch" set to true)
___
<a id="findone"></a>
### findOne
▸ **findOne**(selection: *`any`*, fields: *`any`*, options: *`any`*, callback?: *`any`*): `Promise`<`any`>
*Defined in [collection/Collection.ts:332](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L332)*
Finds the first matching document
*__method__*: Collection#findOne
**Parameters:**
| Param | Type |
| ------ | ------ |
| selection | `any` |
| fields | `any` |
| options | `any` |
| `Optional` callback | `any` |
**Returns:** `Promise`<`any`>
Returns a promise with the first matching document of the collection
___
<a id="insert"></a>
### insert
▸ **insert**(doc: *`any`*, options: *`any`*, callback?: *`any`*): `Promise`<`any`>
*Defined in [collection/Collection.ts:136](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L136)*
Inserts a document into the collection
*__method__*: Collection#insert
**Parameters:**
| Param | Type | Description |
| ------ | ------ | ------ |
| doc | `any` | Document to be inserted |
| options | `any` |
| `Optional` callback | `any` |
**Returns:** `Promise`<`any`>
Returns a promise with the inserted document
___
<a id="remove"></a>
### remove
▸ **remove**(selection: *`any`*, options: *`any`*, callback?: *`any`*): `Promise`<`any`[]>
*Defined in [collection/Collection.ts:660](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L660)*
Removes one or many documents
*__method__*: Collection#remove
**Parameters:**
| Param | Type |
| ------ | ------ |
| selection | `any` |
| options | `any` |
| `Optional` callback | `any` |
**Returns:** `Promise`<`any`[]>
Promise with the deleted documents
___
<a id="removebackup"></a>
### removeBackup
▸ **removeBackup**(backupID: *`any`*): `string`
*Defined in [collection/Collection.ts:922](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L922)*
*__ignore__*:
**Parameters:**
| Param | Type |
| ------ | ------ |
| backupID | `any` |
**Returns:** `string`
___
<a id="rename"></a>
### rename
▸ **rename**(newName: *`any`*): `this`
*Defined in [collection/Collection.ts:1044](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L1044)*
*__ignore__*:
**Parameters:**
| Param | Type |
| ------ | ------ |
| newName | `any` |
**Returns:** `this`
___
<a id="restore"></a>
### restore
▸ **restore**(backupID: *`any`*, callback: *`any`*): `Promise`<`string`>
*Defined in [collection/Collection.ts:957](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L957)*
*__ignore__*:
**Parameters:**
| Param | Type |
| ------ | ------ |
| backupID | `any` |
| callback | `any` |
**Returns:** `Promise`<`string`>
___
<a id="save"></a>
### save
▸ **save**(doc: *`any`*, options: *`any`*, callback?: *`any`*): `Promise`<`any`>
*Defined in [collection/Collection.ts:826](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L826)*
Insert or update a document. If the document has an "_id" is an update (with upsert), if not is an insert.
*__method__*: Collection#save
**Parameters:**
| Param | Type | Description |
| ------ | ------ | ------ |
| doc | `any` | Document to be inserted/updated |
| options | `any` |
| `Optional` callback | `any` |
**Returns:** `Promise`<`any`>
Returns a promise with the inserted document or the update information
___
<a id="update"></a>
### update
▸ **update**(selection: *`any`*, update: *`any`*, options: *`any`*, callback?: *`any`*): `Promise`<`any`>
*Defined in [collection/Collection.ts:411](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L411)*
Updates one or many documents
*__method__*: Collection#update
**Parameters:**
| Param | Type |
| ------ | ------ |
| selection | `any` |
| update | `any` |
| options | `any` |
| `Optional` callback | `any` |
**Returns:** `Promise`<`any`>
Returns a promise with the update/insert (if upsert=true) information
___
<a id="checkcollectionname"></a>
### `<Static>` checkCollectionName
▸ **checkCollectionName**(collectionName: *`any`*): `void`
*Defined in [collection/Collection.ts:1065](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L1065)*
*__ignore__*:
**Parameters:**
| Param | Type |
| ------ | ------ |
| collectionName | `any` |
**Returns:** `void`
___
## Object literals
<a id="_nocreatemodifiers"></a>
### `<Static>` _noCreateModifiers
**_noCreateModifiers**: *`object`*
*Defined in [collection/Collection.ts:53](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L53)*
*__ignore__*:
<a id="_nocreatemodifiers._pop"></a>
#### $pop
**● $pop**: *`boolean`* = true
*Defined in [collection/Collection.ts:55](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L55)*
___
<a id="_nocreatemodifiers._pull"></a>
#### $pull
**● $pull**: *`boolean`* = true
*Defined in [collection/Collection.ts:57](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L57)*
___
<a id="_nocreatemodifiers._pullall"></a>
#### $pullAll
**● $pullAll**: *`boolean`* = true
*Defined in [collection/Collection.ts:58](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L58)*
___
<a id="_nocreatemodifiers._rename"></a>
#### $rename
**● $rename**: *`boolean`* = true
*Defined in [collection/Collection.ts:56](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L56)*
___
<a id="_nocreatemodifiers._unset"></a>
#### $unset
**● $unset**: *`boolean`* = true
*Defined in [collection/Collection.ts:54](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/collection/Collection.ts#L54)*
___
___