Socket
Socket
Sign inDemoInstall

modm

Package Overview
Dependencies
19
Maintainers
3
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

modm

A MongoDB Object Document Mapper (ODM)


Version published
Maintainers
3
Weekly downloads
2
decreased by-66.67%
Bundle size
110.8 kB
Minified + gzipped

Weekly downloads

Readme

Source

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

NameExampleDescription
type"string"Possible values: "Array", "Boolean", "Buffer", "Date", "Number", "Object", "ObjectID"
requiredtruePossible values: true, false
default"this is a string default value"The default value. Can by any type of data.
validatefunction () {}Validate function
manipulatefunction () {}Manipulate function
pre"my prefix "A string to prefix the value
post" my suffix"A string to suffix the value
charStyle"normal"Possible values: "normal", "uppercase", "lowercase"
parseDD.MM.YYYFor `date` types only. A string value passed if available to the Moment.js date parser.
trimtrueBoolean value. Trim or not?
maxLength5Max length. Integer.
minLength1Min length. Integer.
max5number
min-3number
livetrueBoolean 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.

Keywords

FAQs

Last updated on 21 Jan 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc