0.0.1 • Published 10 years ago

missy-mongodb v0.0.1

Weekly downloads
2
License
-
Repository
github
Last release
10 years ago

Missy MongoDB driver

MongoDB database driver for Missy.

Usage

Creating a Schema

Simple form:

var missy = require('missy').loadDriver('mongodb')
    ;

var schema = new missy.Schema('mongodb://localhost/test', {
    connect: {
        // Native MongoClient options
        db: {
            journal: true,
            native_parser: true
        },
        server: {
            ssl: false,
            logger: true
        }
    }
});

Full form with manual driver initialization:

var missy = require('missy').loadDriver('mongodb'),
    mongodb = require('mongodb')
    ;

// Driver
var driver = new MongodbDriver(function(){ // Custom connecter function
    // A promise for a client
    return Q.nmcall(mongodb.MongoClient, 'connect',
        'mongodb://localhost/test',
        { db: { journal: true } }
    ); // -> db
});

// Schema
var schema = new missy.Schema(driver);

Type Handlers

The driver defines the following custom types:

  • 'ObjectID': MongoDB ObjectID property.
var User = schema.define('User', {
    _id: { type: 'ObjectID' }
}, { pk: '_id' });

User.insert({ _id: 'aaaaaaaaaaaa' });

Tests

In order to run the tests, you need to define the 'MISSY_MONGODB` environment variable. The tests will work on the provided DB and clean-up the created collections afterwards:

$ MISSY_MONGODB="mongodb://localhost/test" npm test