Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Mongodb Object Document Mapper
JavaScript

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
example
lib
.gitignore
README.md
index.js
package.json

README.md

MODM

Mongodb Object Document Mapper

Example

var modm = require('modm');

// define a schema
schema = new modm.Schema({field: String});

// create db connection
model = modm('myDb', {
    host: '127.0.0.1',
    port: 27017,
    server: {pooSize: 5},
    db: {w: 1}
});

// get a collection
myCollection = model('myCollection', schema);

// db operations
myCollection.insert({data: 1}, function (err, item) {
   //...
});

// connect first, otherwise find will return undefined
// instead of a cursor.
model.connect(function (err, db) {
    var cursor = myCollection.find({/*query*/});
    cursor.toArray(function () {
        //...
    });
});

// ..or access the cursor in the callback
myCollection.find({/*query*/}, function (err, cursor) {
    cursor.toArray(function () {
        //...
    });
});

Info

Results of atomic operations are not validated.

Schema options

Name Example Description
type "string" Possible values: "Array", "Boolean", "Buffer", "Date", "Number", "Object", "ObjectID"
required true Possible values: true, false
default "this is a string default value" The default value. Can by any type of data.
validate function () {} Validate function
manipulate function () {} Manipulate function
pre "pre"
post "post"
charStyle "normal" Possible values: "normal", "uppercase", "lowercase"
trim true Boolean value. Trim or not?
maxLength 5 Max length. Integer.
minLength 1 Min length. Integer.
max 5 number
min -3 number
live true Boolean value: true or false. Not yet implemented

License

"THE BEER-WARE LICENSE" (Revision 42):

adrian@ottiker.com wrote this code. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.

Something went wrong with that request. Please try again.