Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

101 lines (64 sloc) 2.471 kb

Mongoose: MongoDB utility library with ORM-like functionality

The goal of Mongoose is to provide a extremely simple interface for MongoDB.

Goals

  • Reduce the burden of dealing with nested callback from async operations.
  • Provide a simple yet rich set of APIs.
  • Still have easy access to the database/collection.

Quick Start

  User = require('mongoose').Storage
        .connect({host: 'localhost', port : 34324})
        .bindModel(__dirname+'/models/User');

  User.find(query).each(function(user){
      // do something to matching user
  });

  User
    .find
    .update
    .upsert
    .insert
    .count
    .distinct
    .mapReduce
    .remove
    .flush

  each : [find,update,upsert,insert,distinct,remove]
  get/one [find,count,mapReduce]  

  User.collection = native collection instance
  User.database = native database instance.



  User.update(query)

  User.insert(object);

  var user = new User(object);







/*
  loadModels takes either an array of specifc model paths. 
  Or it can take a require path that ends in a backslash (/)
  it will load all .js files within the directory. 

  The return is an object whose keys are the basename and the 
  values is the Model instance 

  ex:

  var storage = Mogoose.connect({...}),
  m = Models = storage.loadModels('./models/');

  m.user.find({}).each()

  m.user.find().one(function(){})

*/

Example

mongoose = require('../../mongoose/').configure({
        dev : { master : { host : 'localhost',  port : 27017, name : 'test', options : {auto_reconnect : true}} }
    }),      
devStore = mongoose.connect('dev'),
models = require('../lib/model').Model,
models.load('User',devStore,function(User){

});

Requirements

Future

Revisions

Jump to Line
Something went wrong with that request. Please try again.