[Mongo Portable](../README.md) > [MongoPortable](../classes/mongoportable.md)

# Class: MongoPortable

MongoPortable
*__module__*: MongoPortable

*__since__*: 0.0.1

*__classdesc__*: Portable database with persistence and MongoDB-like API

*__param__*: Name of the database.

## Hierarchy

 [EventEmitter](eventemitter.md)

**↳ MongoPortable**

## Index

### Constructors

* [constructor](mongoportable.md#constructor)

### Properties

* [_collections](mongoportable.md#_collections)
* [_databaseName](mongoportable.md#_databasename)
* [_stores](mongoportable.md#_stores)
* [logger](mongoportable.md#logger)
* [pkFactory](mongoportable.md#pkfactory)
* [_connHelper](mongoportable.md#_connhelper)

### Methods

* [addStore](mongoportable.md#addstore)
* [addStoreFromFunction](mongoportable.md#addstorefromfunction)
* [addStoreFromObject](mongoportable.md#addstorefromobject)
* [collection](mongoportable.md#collection)
* [collectionNames](mongoportable.md#collectionnames)
* [collections](mongoportable.md#collections)
* [collectionsInfo](mongoportable.md#collectionsinfo)
* [createCollection](mongoportable.md#createcollection)
* [createIndex](mongoportable.md#createindex)
* [dereference](mongoportable.md#dereference)
* [dropCollection](mongoportable.md#dropcollection)
* [dropDatabase](mongoportable.md#dropdatabase)
* [dropIndex](mongoportable.md#dropindex)
* [emit](mongoportable.md#emit)
* [ensureIndex](mongoportable.md#ensureindex)
* [fetchCollections](mongoportable.md#fetchcollections)
* [indexInformation](mongoportable.md#indexinformation)
* [reIndex](mongoportable.md#reindex)
* [renameCollection](mongoportable.md#renamecollection)
* [use](mongoportable.md#use)
* [getInstance](mongoportable.md#getinstance)

### Object literals

* [options](mongoportable.md#options)

---

## Constructors

<a id="constructor"></a>

###  constructor

⊕ **new MongoPortable**(databaseName: *`string`*, options: *`any`*): [MongoPortable](mongoportable.md)

*Overrides [EventEmitter](eventemitter.md).[constructor](eventemitter.md#constructor)*

*Defined in [core/MongoPortable.ts:40](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L40)*

**Parameters:**

| Param | Type |
| ------ | ------ |
| databaseName | `string` |
| options | `any` |

**Returns:** [MongoPortable](mongoportable.md)

___

## Properties

<a id="_collections"></a>

### `<Private>` _collections

**● _collections**: *`__type`*

*Defined in [core/MongoPortable.ts:38](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L38)*

___
<a id="_databasename"></a>

### `<Private>` _databaseName

**● _databaseName**: *`string`*

*Defined in [core/MongoPortable.ts:40](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L40)*

___
<a id="_stores"></a>

### `<Private>` _stores

**● _stores**: *`Array`< `any` &#124; `function`>*

*Defined in [core/MongoPortable.ts:39](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L39)*

___
<a id="logger"></a>

### `<Protected>` logger

**● logger**: *`JSWLogger`*

*Overrides [EventEmitter](eventemitter.md).[logger](eventemitter.md#logger)*

*Defined in [core/MongoPortable.ts:36](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L36)*

___
<a id="pkfactory"></a>

###  pkFactory

**● pkFactory**: *`any`*

*Defined in [core/MongoPortable.ts:34](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L34)*

___
<a id="_connhelper"></a>

### `<Static>``<Private>` _connHelper

**● _connHelper**: *[ConnectionHelper](connectionhelper.md)* =  new ConnectionHelper()

*Defined in [core/MongoPortable.ts:31](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L31)*

___

## Methods

<a id="addstore"></a>

###  addStore

▸ **addStore**(store: *`any`*): `this`

*Defined in [core/MongoPortable.ts:91](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L91)*

Adds a custom stores for remote and local persistence

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| store | `any` |  The custom store |

**Returns:** `this`
this - The current Instance

___
<a id="addstorefromfunction"></a>

### `<Private>` addStoreFromFunction

▸ **addStoreFromFunction**(storeClass: *`any`*): `this`

*Defined in [core/MongoPortable.ts:106](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L106)*

**Parameters:**

| Param | Type |
| ------ | ------ |
| storeClass | `any` |

**Returns:** `this`

___
<a id="addstorefromobject"></a>

### `<Private>` addStoreFromObject

▸ **addStoreFromObject**(store: *`any`*): `this`

*Defined in [core/MongoPortable.ts:112](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L112)*

**Parameters:**

| Param | Type |
| ------ | ------ |
| store | `any` |

**Returns:** `this`

___
<a id="collection"></a>

###  collection

▸ **collection**(collectionName: *`any`*, options: *`any`*, callback?: *`any`*): `Promise`<[Collection](collection.md)>

*Defined in [core/MongoPortable.ts:254](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L254)*

Creates a collection on a server pre-allocating space, need to create f.ex capped collections.
*__method__*: MongoPortable#collection

*__fires__*: {@link MongoStore#createCollection}

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| collectionName | `any` |  the collection name we wish to access. |
| options | `any` |
| `Optional` callback | `any` |

**Returns:** `Promise`<[Collection](collection.md)>

___
<a id="collectionnames"></a>

###  collectionNames

▸ **collectionNames**(options: *`any`*, callback?: *`any`*): `any`[]

*Defined in [core/MongoPortable.ts:205](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L205)*

Get the list of all collection names for the specified db, by calling MongoPortable#collections with \[options.namesOnly = true\]
*__method__*: MongoPortable#collectionNames

**Parameters:**

| Param | Type |
| ------ | ------ |
| options | `any` |
| `Optional` callback | `any` |

**Returns:** `any`[]

{@link MongoPortable#collections}

___
<a id="collections"></a>

###  collections

▸ **collections**(options: *`any`*, callback?: *`any`*): `any`[]

*Defined in [core/MongoPortable.ts:155](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L155)*

Get the list of all collection for the specified db
*__method__*: MongoPortable#collections

**Parameters:**

| Param | Type |
| ------ | ------ |
| options | `any` |
| `Optional` callback | `any` |

**Returns:** `any`[]

___
<a id="collectionsinfo"></a>

###  collectionsInfo

▸ **collectionsInfo**(collectionName: *`any`*, callback?: *`any`*): `void`

*Defined in [core/MongoPortable.ts:128](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L128)*

Returns a cursor to all the collection information.
*__todo__*: Implement

**Parameters:**

| Param | Type |
| ------ | ------ |
| collectionName | `any` |
| `Optional` callback | `any` |

**Returns:** `void`

___
<a id="createcollection"></a>

###  createCollection

▸ **createCollection**(collectionName: *`any`*, options: *`any`*, callback?: *`any`*): `Promise`<[Collection](collection.md)>

*Defined in [core/MongoPortable.ts:312](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L312)*

Alias for {@link MongoPortable#collection}
*__method__*: MongoPortable#createCollection

**Parameters:**

| Param | Type |
| ------ | ------ |
| collectionName | `any` |
| options | `any` |
| `Optional` callback | `any` |

**Returns:** `Promise`<[Collection](collection.md)>

___
<a id="createindex"></a>

###  createIndex

▸ **createIndex**(collectionName: *`any`*, fieldOrSpec: *`any`*, options: *`any`*, callback: *`any`*): `void`

*Defined in [core/MongoPortable.ts:452](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L452)*

Creates an index on the collection.
*__method__*: MongoPortable#createIndex

*__todo__*: Implement

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| collectionName | `any` |  Name of the collection to create the index on. |
| fieldOrSpec | `any` |  FieldOrSpec that defines the index. |
| options | `any` |
| callback | `any` |

**Returns:** `void`

___
<a id="dereference"></a>

###  dereference

▸ **dereference**(dbRef: *`any`*, callback: *`any`*): `void`

*Defined in [core/MongoPortable.ts:586](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L586)*

Dereference a dbref, against a db
*__todo__*: Implement

*__ignore__*: 

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| dbRef | `any` |  db reference object we wish to resolve. |
| callback | `any` |

**Returns:** `void`

___
<a id="dropcollection"></a>

###  dropCollection

▸ **dropCollection**(collectionName: *`any`*, callback?: *`any`*): `Promise`<`boolean`>

*Defined in [core/MongoPortable.ts:326](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L326)*

Drop a collection from the database, removing it permanently. New accesses will create a new collection.
*__method__*: MongoPortable#dropCollection

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| collectionName | `any` |  The name of the collection we wish to drop. |
| `Optional` callback | `any` |

**Returns:** `Promise`<`boolean`>
Promise with "true" if dropped successfully

___
<a id="dropdatabase"></a>

###  dropDatabase

▸ **dropDatabase**(callback?: *`any`*): `Promise`<`boolean`>

*Defined in [core/MongoPortable.ts:549](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L549)*

Drop the whole database.
*__method__*: MongoPortable#dropDatabase

**Parameters:**

| Param | Type |
| ------ | ------ |
| `Optional` callback | `any` |

**Returns:** `Promise`<`boolean`>
Promise with "true" if dropped successfully

___
<a id="dropindex"></a>

###  dropIndex

▸ **dropIndex**(collectionName: *`any`*, indexName: *`any`*, callback: *`any`*): `void`

*Defined in [core/MongoPortable.ts:502](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L502)*

Drop an index on a collection.
*__method__*: MongoPortable#dropIndex

*__todo__*: Implement

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| collectionName | `any` |  The name of the collection where the command will drop an index. |
| indexName | `any` |  Name of the index to drop. |
| callback | `any` |

**Returns:** `void`

___
<a id="emit"></a>

###  emit

▸ **emit**(name: *`string`*, args: *`object`*): `Promise`<`void`>

*Overrides [EventEmitter](eventemitter.md).[emit](eventemitter.md#emit)*

*Defined in [core/MongoPortable.ts:63](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L63)*

**Parameters:**

| Param | Type |
| ------ | ------ |
| name | `string` |
| args | `object` |

**Returns:** `Promise`<`void`>

___
<a id="ensureindex"></a>

###  ensureIndex

▸ **ensureIndex**(collectionName: *`any`*, fieldOrSpec: *`any`*, options: *`any`*, callback: *`any`*): `void`

*Defined in [core/MongoPortable.ts:487](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L487)*

Ensures that an index exists, if it does not it creates it
*__method__*: MongoPortable#ensureIndex

*__todo__*: Implement

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| collectionName | `any` |  Name of the collection to create the index on. |
| fieldOrSpec | `any` |  FieldOrSpec that defines the index. |
| options | `any` |
| callback | `any` |

**Returns:** `void`

___
<a id="fetchcollections"></a>

###  fetchCollections

▸ **fetchCollections**(options: *`any`*, callback?: *`any`*): `any`[]

*Defined in [core/MongoPortable.ts:137](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L137)*

Alias for {@link MongoPortable#collections}
*__method__*: MongoPortable#fetchCollections

**Parameters:**

| Param | Type |
| ------ | ------ |
| options | `any` |
| `Optional` callback | `any` |

**Returns:** `any`[]

___
<a id="indexinformation"></a>

###  indexInformation

▸ **indexInformation**(collectionName: *`any`*, options: *`any`*, callback: *`any`*): `void`

*Defined in [core/MongoPortable.ts:536](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L536)*

Retrieves this collections index info.
*__method__*: MongoPortable#indexInformation

*__todo__*: Implement

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| collectionName | `any` |  The name of the collection. |
| options | `any` |
| callback | `any` |

**Returns:** `void`

___
<a id="reindex"></a>

###  reIndex

▸ **reIndex**(collectionName: *`any`*, callback: *`any`*): `void`

*Defined in [core/MongoPortable.ts:517](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L517)*

Reindex all indexes on the collection Warning: "reIndex" is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.
*__method__*: MongoPortable#reIndex

*__todo__*: Implement

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| collectionName | `any` |  The name of the collection to reindex |
| callback | `any` |

**Returns:** `void`

___
<a id="renamecollection"></a>

###  renameCollection

▸ **renameCollection**(fromCollection: *`any`*, toCollection: *`any`*, callback?: *`any`*): `Promise`<[Collection](collection.md)>

*Defined in [core/MongoPortable.ts:368](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L368)*

Rename a collection.
*__method__*: MongoPortable#renameCollection

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| fromCollection | `any` |  The name of the current collection we wish to rename. |
| toCollection | `any` |  The new name of the collection. |
| `Optional` callback | `any` |

**Returns:** `Promise`<[Collection](collection.md)>
Promise with the renamed collection

___
<a id="use"></a>

###  use

▸ **use**(name: *`any`*, obj: *`any`*): `void`

*Defined in [core/MongoPortable.ts:76](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L76)*

Middleware functions

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| name | `any` |  Name of the middleware: <ul> <li>"store": Add a custom store</li> </ul> |
| obj | `any` |

**Returns:** `void`

___
<a id="getinstance"></a>

### `<Static>` getInstance

▸ **getInstance**(name: *`string`*): [IConnection](../interfaces/iconnection.md)

*Defined in [core/MongoPortable.ts:608](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/core/MongoPortable.ts#L608)*

Retrieves the instance of that DDBB name

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| name | `string` |  The DDBB name |

**Returns:** [IConnection](../interfaces/iconnection.md)
- The DDBB instance

___

## Object literals

<a id="options"></a>

###  options

**options**: *`object`*

*Inherited from [EventEmitter](eventemitter.md).[options](eventemitter.md#options)*

*Defined in [emitter/EventEmitter.ts:7](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/emitter/EventEmitter.ts#L7)*

<a id="options.autorejecttimeout"></a>

####  autoRejectTimeout

**● autoRejectTimeout**: *`number`* = 60000

*Defined in [emitter/EventEmitter.ts:9](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/emitter/EventEmitter.ts#L9)*

___
<a id="options.log"></a>

####  log

**● log**: *`object`*

*Defined in [emitter/EventEmitter.ts:8](https://github.com/EastolfiWebDev/MongoPortable/blob/d5d3826/src/emitter/EventEmitter.ts#L8)*

#### Type declaration

___

___

