modm
v0.4.1
Published
A MongoDB Object Document Mapper (ODM)
Downloads
20
Readme
MODM
Mongodb Object Document Mapper
Example
var modm = require("modm");
// define a schema
var schema = new modm.Schema({field: String});
// create db connection
var model = modm("myDb", {
host: "127.0.0.1",
port: 27017,
server: {pooSize: 5},
db: {w: 1}
});
// get a collection
var 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
License
"THE BEER-WARE LICENSE" (Revision 42):
[email protected] 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.