Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/codesignal/meteor-protomongo
Extensions to Meteor's Mongo.Collection prototype
https://github.com/codesignal/meteor-protomongo
insert meteor meteor-protomongo promise upsert
Last synced: about 2 hours ago
JSON representation
Extensions to Meteor's Mongo.Collection prototype
- Host: GitHub
- URL: https://github.com/codesignal/meteor-protomongo
- Owner: CodeSignal
- Created: 2018-09-10T21:32:05.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-07-12T07:15:37.000Z (4 months ago)
- Last Synced: 2024-11-15T07:54:56.305Z (about 20 hours ago)
- Topics: insert, meteor, meteor-protomongo, promise, upsert
- Language: JavaScript
- Size: 2.28 MB
- Stars: 6
- Watchers: 7
- Forks: 2
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
@codesignal/meteor-protomongo
[![](http://img.shields.io/npm/dm/@codesignal/meteor-protomongo.svg?style=flat)](https://www.npmjs.com/package/@codesignal/meteor-protomongo) [![npm version](https://badge.fury.io/js/%40codesignal%2Fmeteor-protomongo.svg)](https://www.npmjs.com/package/@codesignal/meteor-protomongo)
=**Monkey-patches to `meteor/mongo`.**
*Helpful for working with indexes and transitioning away from Fibers.*
**Update, November 2022:**
Meteor 2.8 updated the core `meteor/mongo` package to add `*Async` versions of Mongo methods by default. See: https://github.com/meteor/meteor/pull/11605
Since the new core methods have identical signatures to the ones previously provided by this package, the 3.x release of this package has been updated to remove the overlapping methods.
Now, the package only includes helpers related to working with indexes or aggregation.
## Description
This package extends the `Collection` prototype from `meteor/mongo` with a few handy helpers related to indexes and aggregation. It's intended for use only with projects built with [Meteor](https://www.meteor.com/).
### API
#### Collection Prototype
```js
Collection.updateManyAsync(selector, modifier, ?options);
```Same as `Collection.updateAsync`; passes `{ multi: true }` in addition to the passed `options`.
```js
Collection.getIndexes();
```Returns a Promise that is resolved with an array of indexes for this collection. For example, you might see this for a users collection with only an index on ID:
```js
[{ v: 2, key: { _id: 1 }, name: '_id_', ns: 'meteor.users' }]
``````js
Collection.ensureIndex(selector, options);
```Ensures an index exists. Similar to the built-in `createIndex`, but handles the case where the index already exists with different options by removing and re-adding the index with the new options. To ensure your database has the same indexes across different environments, you might want to add `ensureIndex` calls to `Meteor.startup`.
```js
Collection.ensureNoIndex(selector);
```The reverse of `ensureIndex`. You might want to call this in `Meteor.startup` to make sure an index has been removed in all of your deployed environments.
```js
Collection.aggregate(pipeline, ?options);
```Exposes the [aggregate method](https://www.mongodb.com/docs/manual/reference/method/db.collection.aggregate/). This removes the need to use `rawCollection()` every time you want to aggregate.
## Install
```bash
npm install @codesignal/meteor-protomongo
```After the package is installed, add the following few lines in a file that's going to be loaded on startup:
```js
import { Mongo } from 'meteor/mongo';
import ProtoMongo from '@codesignal/meteor-protomongo';ProtoMongo.extendCollection(Mongo);
```## Building Locally
After checking out this repo, run...
```sh
npm install
npm run build
```To do local checks:
```sh
npm run eslint
```## Contributing
If you'd like to make a contribution, please open a pull request in [package repository](https://github.com/CodeSignal/meteor-protomongo).
If you want (and have the right permissions) to publish a new version, please follow the instructions below:
* Make sure you have [NPM](https://www.npmjs.com/) account and are a member of [codesignal](https://www.npmjs.com/org/codesignal) organization;
* Follow instructions from [npm docs](https://docs.npmjs.com/getting-started/publishing-npm-packages) to set up NPM user in your local environment;
* Update package version and push changes to git by running these commands: `npm version `, `git push origin master`, `git push --tags`;
* Publish the updated package with `npm publish --access public`.## License
MIT