# feathers-mongo-collections

> MongoDB collections service for FeathersJS.

Latest version **0.0.3** (published 2015-02-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install feathers-mongo-collections
pnpm add feathers-mongo-collections
yarn add feathers-mongo-collections
bun add feathers-mongo-collections
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2015-02-15 |
| First published | 2015-02-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Marshall Thompson |
| Maintainers | marshallswain |
| Keywords | feathers, feathers-service, REST, Socket.io, realtime, mongodb, mongo, service |

## Links

- npm: https://www.npmjs.com/package/feathers-mongo-collections
- Repository: https://github.com/marshallswain/feathers-mongo-collections
- Issues: https://github.com/marshallswain/feathers-mongo-collections/issues
- npm.io page: https://npm.io/package/feathers-mongo-collections

## Dependencies (1)

- [async](https://npm.io/package/async.md) ~0.8.0

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 0.0.3 (latest) — 2015-02-15
- 0.0.2 — 2015-02-14
- 0.0.1 — 2015-02-11

## README

feathers-mongo-collections Service
=========================

[![NPM](https://nodei.co/npm/feathers-mongo-collections.png?downloads=true&stars=true)](https://nodei.co/npm/feathers-mongo-collections/)


> Create a [FeatherJS](https://github.com/feathersjs) service for managing collections in a [MongoDB](http://mongodb.org/)database.

`feathers-mongo-collections` works just like a standard [FeatherJS](https://github.com/feathersjs) service, except for the get/findOne.  It uses the collection name as the `id` value when performing `create`, `update`, and `remove`.

## Installation

```bash
npm install feathers-mongo-database --save
```

## Getting Started
To create an instance of a `feathers-mongo-collections` service, first connect to your MongoDB database.  Then pass the connected database into `feathers-mongo-collections`.

```js
var feathers = require('feathers');
var feathersMongoColls = require('feathers-mongo-collections');
var MongoClient = require('mongodb').MongoClient;
var dbAddress = 'mongodb://localhost:27017/feathers-tuts';

// Prep the Feathers server.
var app = feathers()
  .use(feathers.static(__dirname + '/public'))
  .use(bodyParser.json())
  .use(bodyParser.urlencoded({extended: true}))
  .configure(feathers.socketio())
  .configure(feathers.rest());

// Connect to the database.
MongoClient.connect(dbAddress, function(err, db) {
    // Create a `feathers-mongo-collections` instance.
    app.use('/feathers-tuts/_collections', feathersMongoColls(db))
});

// Start the server.
var port = 8081;
app.listen(port, function() {
  // app.use('/api/tasks', require('./services/tasks'));
  console.log('Feathers server listening on port ' + port);
});

```

## API

### find()
`find()` currently accepts no parameters.  It simply returns an array of all of the collections in the connected db.  It returns data in this format:

```json
[
    {
        "size": "",
        "max": "",
        "capped": false,
        "name": "users",
        "stats": {
          "ns": "feathers-tuts.users",
          "count": 6,
          "size": 1360,
          "avgObjSize": 226.66666666666666,
          "storageSize": 40960,
          "numExtents": 2,
          "nindexes": 2,
          "lastExtentSize": 32768,
          "paddingFactor": 1,
          "systemFlags": 1,
          "userFlags": 0,
          "totalIndexSize": 16352,
          "indexSizes": {
            "_id_": 8176,
            "id_1": 8176
          },
          "ok": 1
        }
    },
    {
        "name": "employees",
        "stats": {
          "ns": "feathers-tuts.employees",
          "count": 0,
          "size": 0,
          "storageSize": 8192,
          "numExtents": 1,
          "nindexes": 2,
          "lastExtentSize": 8192,
          "paddingFactor": 1,
          "systemFlags": 1,
          "userFlags": 0,
          "totalIndexSize": 16352,
          "indexSizes": {
            "_id_": 8176,
            "id_1": 8176
          },
          "ok": 1
        }
    }
]
```

***

### get()
Not implemented

***

### create(name)
Provide a collection `name`.  If `create` is successful, the data returned will look like this:
```json
{
    "name": "MyCollection"
}
```

If the collection already exists, the existing collection will not be overwritten.  MongoDB doesn't actually require creating a collection before inserting a document.  If you insert a document into a collection that doesn't exist, the collection will be created upon insert, so this method is mostly a convenience method for web apps.

***

### update(name)
For update operations, the collection name replaces the REST id. Pass the current db name as the id, and the new name in the data.

```
PUT /api/localhost:27017/feathers-tuts/_collections/MyCollection HTTP/1.1
Content-Type: application/x-www-form-urlencoded

name=NewCollectionName
```

If the update operation is successful, the response will look like this:
```json
{
    "name": "NewCollectionName"
}
```

If the name / id doesn't exist, the following MongoDB error will be returned:
```
"exception: source namespace does not exist"
```

If the target name already exists, the following MongoDB error will be returned:
```
"exception: target namespace exists"
```

***

### remove(name)
For remove operations, the collection name is used as the REST id.

Successful remove operations will return `true`.

If the named collection cannot be found, the following MongoDB error will be returned:
```
"ns not found"
```

***

## License

[MIT](LICENSE)

## Author

[Marshall Thompson](https://github.com/marshallswain)

---
_Source: https://npm.io/package/feathers-mongo-collections · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
