# mongoose-hose

> Hose is plugin for your Mongoose schema that allows a fixed length array of nested docs. Useful for storing only the newest subdocs while leaving he oldest to be lost. When a doc is pushed into the array, if length is more than the limit the oldest will b

Latest version **2.1.1** (published 2017-08-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install mongoose-hose
pnpm add mongoose-hose
yarn add mongoose-hose
bun add mongoose-hose
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2017-08-06 |
| First published | 2017-05-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jason McIver |
| Maintainers | jaymc |
| Keywords | mongoose, plugin, hose, buffer, chat, IOT, circular buffer, circular queue, ring buffer, FIFO, capped array |

## Links

- npm: https://www.npmjs.com/package/mongoose-hose
- Repository: https://github.com/JayMc/mongoose-hose
- Issues: https://github.com/JayMc/mongoose-hose/issues
- npm.io page: https://npm.io/package/mongoose-hose

## 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
- [@temporal-architect/claude-plugin](https://npm.io/package/@temporal-architect/claude-plugin.md) — 335 weekly downloads

## Recent versions

- 2.1.1 (latest) — 2017-08-06
- 2.1.0 — 2017-05-28
- 1.0.0 — 2017-05-14

## README

# mongoose-hose
<p align="center">
	<img height="200" width="200" src="https://raw.githubusercontent.com/JayMc/mongoose-hose/master/logo.png">
</p>

A capped array similar to Mongo's capped collection. The array has a fixed length providing a First in First out (FIFO) behavior. Objects in the array will be automatically pushed down as newer ones are added, when the oldest exceeds the array length it will be 'popped off' (deleted).

This plugin provides a way of storing the latest data in a parent document and saves having to secondarily fetch (or join) data from a related collection. 

## use cases
A chat-room schema with this plugin can contain the latest messages without retrieving multiple documents from the messages schema.

## Basic usage
```javascript
MySchema = mongoose.Schema({
	title: String,
});

MySchema.plugin(hose, /* options */);
```

## options
```javascript
const options = {
	limit: 100, // capped array length - number of items which can be stored before popping off.
	arrayName: 'hose', // name of the capped array hose containing the subdocs
}
```

## Basic usage
### save to hose
Callback
```javascript
const newComment = {
	body: 'Hello',
}

MySchema.hoseInsert(parent_id, newComment, function (err, doc) {

})
```

Promise
```javascript
MySchema.hoseInsert(parent_id, newComment)
	.then(result => {

	})
	.catch(error => {

	})
```

### update hose item
Callback
```javascript
MySchema.hoseUpdate(parent_id, hoseItem_id, updatedComment, function (err, doc) {

})
```

Promise
```javascript
MySchema.hoseUpdate(parent_id, hoseItem_id, updatedComment)
	.then(result => {

	})
	.catch(error => {

	})
```

## get (dev) going
* nvm use
* npm i
* ??
* npm run test

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