ma
mongeese-array
npm i mongeese-array
ma

mongeese-array

Supercharged Mongoose array class

by Zeke Nierenberg

0.0.3 (see all)License:ISCTypeScript:Not Found
npm i mongeese-array
Readme

Codeship Status for zekenie/mongeese

Dependencies

Mongeese

This library supercharges the mongoose Array class by adding some async functional methods, and some extra goodies.

Installation

$ npm install mongeese-array --save

Before you define your models, require mongeese. It will modify the prototypes of several mongoose classes, so you can't require it after you make your models.

Async methods

Imagine you had a user class with an array of objectId references to kittens. With mongeese, you can do this

var iterator = function(oneKitten,done) {
  done(null,oneKitten.name)
}

someUser.kittens.asyncMap(iterator,function(err,kittenNames) {
  // kitten names -> ['fluffy', 'cuddles', ...]
})

Mongeese will ensure that the path has been populated, but will not populate an already populated path.

Functions available directly from the async library:

  • asyncEach
  • asyncEachLimit
  • asyncMap
  • asyncMapLimit
  • asyncReduce
  • asyncReduceRight
  • asyncSortBy
  • asyncConcat

Invoke

I've added an additional method that async hasn't implemented: invoke. Let's say you wanted to invoke the meow method on all the kittens in a user's kittens array.

someUser.kittens.invoke('meow',arg1,arg2,callback)

After ensuring that the kittens array has been populated, Mongeese will asynchronously call the meow method on each kitten. invoke is really a front for async map, so it is assumes that the function you invoke will act sort of like an iterator.

Development & Contribution

If you see anything wrong or want a feature, pull requests are welcome. To run the test suite

$ npm test

Downloads/wk

2

GitHub Stars

25

LAST COMMIT

8yrs ago

MAINTAINERS

1

CONTRIBUTORS

1

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
0.0.3
latest
8yrs ago
No alternatives found
No tutorials found
Add a tutorial

Rate & Review

100
No reviews found
Be the first to rate