# mongoose-promises

> Mongoose tiny fetcher library built around promises (uses q)

Latest version **0.0.6** (published 2015-04-11) · MIT license · 0 weekly downloads

## Install

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

## 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.6 |
| Published | 2015-04-11 |
| First published | 2015-04-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alexandru Gaman |
| Maintainers | agaman |
| Keywords | mongoose, mongo |

## Links

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

## Dependencies (1)

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

## Recent versions

- 0.0.6 (latest) — 2015-04-11
- 0.0.5 — 2015-04-11
- 0.0.4 — 2015-04-11
- 0.0.3 — 2015-04-10
- 0.0.2 — 2015-04-10
- 0.0.1 — 2015-04-10

## README

This tiny fetcher library will help you write your code in a more semantic fashion :

Methods : 

========================  Constructor  ==============================

-> Constructor = function(model)
	- Specify the model that will be used to query the database

	-> Returns false on undefined model
	-> Returns false if mongoose is not a project dependency
	-> Library instance on valid model

	-> Basic usage :
	var MongooseModel = require(<mongoose model path>);
	// Notice that the constructor is called immediatly
	var MongooseModelPromises = require("mongoose.promises.js")(MongooseModel);

========================  Get method  ==============================

-> Get = function (filter, numberOf)
	- Gets one or more documents from a specified model

	=> Returns : promise

	=> Callback parameters
		=> Success : function(data)
			- data : object, if numberOf not specified or numberOf = 1
					 array, if numberOf present and > 1
		=> Failure : function(message)
			- message : {
				status: "failed",
				message: the error message
			}
	
	-> If filter is not specified, it will return all of the documents
	MongooseModelPromises.Get()
	.then(function(data) {
	    res.status(200).send(data);
	}).fail(function(message) {
	    res.status(400).send(message);
	});

	-> Specifying filter only will return one value

	var filter = {
		_id: req.params.id
	};

	MongooseModelPromises.Get(filter)
	.then(function(data) {
	    res.status(200).send(data);
	}).fail(function(message) {
	    res.status(400).send(message);
	});

	-> Specifying filter and limit

	var filter = {
		_id: req.params.id
	};

	var limit = 20;

	MongooseModelPromises.Get(filter, limit)
	.then(function(data) {
	    res.status(200).send(data);
	}).fail(function(message) {
	    res.status(400).send(message);
	});

========================  Update method  ==============================

-> Update = function(filter, update)
	- Updates a document based on "filter" parameter with keys from the "update" parameter

	=> Returns : promise

	=> Callback parameters
		=> Success : function(message)
			- message : {
				status: "ok",
				old: the document fields before update (all fields)
				new: the document updated fields (the update field provided)
			}
		=> Failure : function(message)
			- message : {
				status: "failed",
				message: the error message
			}

	-> If filter or update objects are undefined (unspecified), false or plain objects {}, the promise will be rejected
		(it will fail)
	Note : internally uses mongoose#model.findOneAndUpdate method
	- Basic usage :
	var filter = {
		_id: req.params.id
	};

	var update = {
		name: "Garfield"
	};

	MongooseModelPromises.Update(filter, update)
    .then(function(message) {
        res.status(200).send(message);
    }).fail(function(message) {
        res.status(400).send(message);
    });

========================  Save method  ==============================

-> Save = function(attrs)
	- Saves a new document based on its attributes

	=> Returns : promise

	=> Callback parameters
		=> Success : function(message)
			- message : {
				status: "ok",
				message: "addition successfull",
				data: the new added document's fields
			}
		=> Failure : function(message)
			- message : {
				status: "failed",
				message: the error message
			}

	-> If attrs object is undefined (unspecified), false or plain object {}, the promise will be rejected
		(it will fail)
	- Basic usage :
	var attrs = {
		name: "Dan The Man"
	};

	MongooseModelPromises.Save(attrs)
    .then(function(message) {
        res.status(200).send(message);
    }).fail(function(message) {
        res.status(400).send(message);
    });

========================  Remove method  ==============================

-> Remove = function(filter)
	- Removes an element from the list

	=> Returns : promise

	=> Callback parameters
		=> Success : function(message)
			- message : {
				status: "ok",
				removed: the removed document's fields
			}
		=> Failure : function(message)
			- message : {
				status: "failed",
				message: the error message
			}

	-> If attrs object is undefined (unspecified), false or plain object {}, the promise will be rejected
		(it will fail)
	- Basic usage :

	var filter = {
		_id: 123
	};

	TemplateModelPromises.Remove(filter)
    .then(function(message) {
        res.status(200).send(message);
    }).fail(function(message) {
        res.status(400).send(message);
    });

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