peerlibrary / meteor-directcollection

Blocking MongoDB API for direct/native access to collections

Home Page:http://atmospherejs.com/peerlibrary/directcollection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DirectCollection

Meteor smart package which provides blocking (using 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 document

Available class methods:

  • command(selector, options, databaseUrl) – executes a command against a Meteor database

Related projects

  • mongo-direct – extends Meteor.Collection with methods for direct/native access

About

Blocking MongoDB API for direct/native access to collections

http://atmospherejs.com/peerlibrary/directcollection

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:CoffeeScript 86.9%Language:JavaScript 13.1%