Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/peerlibrary/meteor-directcollection
Blocking MongoDB API for direct/native access to collections
https://github.com/peerlibrary/meteor-directcollection
meteor meteor-package mongodb
Last synced: 2 months ago
JSON representation
Blocking MongoDB API for direct/native access to collections
- Host: GitHub
- URL: https://github.com/peerlibrary/meteor-directcollection
- Owner: peerlibrary
- License: bsd-3-clause
- Created: 2014-07-05T06:17:28.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2019-09-20T02:05:39.000Z (over 5 years ago)
- Last Synced: 2024-04-15T03:06:58.397Z (9 months ago)
- Topics: meteor, meteor-package, mongodb
- Language: CoffeeScript
- Homepage: http://atmospherejs.com/peerlibrary/directcollection
- Size: 20.5 KB
- Stars: 10
- Watchers: 6
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
DirectCollection
================Meteor smart package which provides [blocking](https://github.com/peerlibrary/meteor-blocking) (using
[fibers](https://github.com/laverdet/node-fibers)) MongoDB API for direct/native access to collections.
It wraps native node.js MongoDB API into an interface similar to Meteor, but allowing direct access to
collections, even if they are not defined through Meteor. It reuses Meteor database connection.It is useful when you want direct access to MongoDB, not bounded by collections defined in Meteor,
but you are working inside Meteor and would like a similar coding style and access to other Meteor
functions which might not work well in callbacks.Installation
------------```
meteor add peerlibrary:directcollection
```API
---Create a direct collection:
```
var directCollection = new DirectCollection(name, makeNewID, databaseUrl);
```It accepts three arguments, name of MongoDB collection, function which returns a document ID which will be used
when inserting documents without `_id` field (default is `Random.id()`) and an optional database URL that can
be used for connecting to external databases.Available collection methods:
* `findToArray(selector, options)` – returns an array of documents
* `findEach(selector, options, eachCallback)` – calls `eachCallback` for each document
* `count(selector, options)` – returns the count
* `findOne(selector, options)` – returns one document
* `insert(document)` – returns document `_id`
* `update(selector, modifier, options)` – returns number of updated documents
* `remove(selector)` – returns number of removed documents
* `renameCollection(newName, options)` – renames the collection
* `findAndModify(selector, sort, document, options)` – modifies and returns a single documentAvailable class methods:
* `command(selector, options, databaseUrl)` – executes a command against a Meteor database
Related projects
----------------* [mongo-direct](http://atmospherejs.com/package/mongo-direct) – extends `Meteor.Collection` with methods for direct/native access