Browse files

updated; README

  • Loading branch information...
1 parent a5726fc commit a234ecdaa5d9455f6a8391de38ce369ab35b8145 @aheckmann aheckmann committed Feb 2, 2013
Showing with 29 additions and 106 deletions.
  1. +29 −106
@@ -2,52 +2,33 @@
Mongoose is a [MongoDB]( object modeling tool designed to work in an asynchronous environment.
-Defining a model is as easy as:
- var Comment = new Schema({
- title : String
- , body : String
- , date : Date
- });
- var BlogPost = new Schema({
- author : ObjectId
- , title : String
- , body : String
- , buf : Buffer
- , date : Date
- , comments : [Comment]
- , meta : {
- votes : Number
- , favs : Number
- }
- });
- var Post = mongoose.model('BlogPost', BlogPost);
## Documentation
## Try it live
<a href="" target="_blank"><img src="" style="width:67px;height:25px;"></a>
-## Installation
-The recommended way is through the excellent [NPM](
+## Support
- $ npm install mongoose
+ - [help forum](
+ - [bug reports](
+ - [10gen support](
+ - (irc) #mongoosejs on freenode
-Otherwise, you can check it in your repository and then expose it:
+## Installation
+First install [node.js]( and [mongodb](
- $ git clone git:// node_modules/mongoose/
+ $ npm install mongoose
-And install dependency modules written on `package.json`.
+## Plugins
-Then you can `require` it:
+Check out the [plugins search site]( to see hundreds of related modules from the community.
- require('mongoose')
+## Overview
-## Connecting to MongoDB
+### Connecting to MongoDB
First, we need to define a connection. If your app uses only one database, you should use `mongose.connect`. If you need to create additional connections, use `mongoose.createConnection`.
@@ -61,7 +42,7 @@ Once connected, the `open` event is fired on the `Connection` instance. If you'r
**Important!** Mongoose buffers all the commands until it's connected to the database. This means that you don't have to wait until it connects to MongoDB in order to define models, run queries, etc.
-## Defining a Model
+### Defining a Model
Models are defined through the `Schema` interface.
@@ -111,7 +92,7 @@ The following example shows some of these features:
Take a look at the example in `examples/schema.js` for an end-to-end example of a typical setup.
-## Accessing a Model
+### Accessing a Model
Once we define a model through `mongoose.model('ModelName', mySchema)`, we can access it through the same function
@@ -135,7 +116,7 @@ Or we can find documents from the same collection
// docs.forEach
-You can also `findOne`, `findById`, `update`, etc. For more details check out [this link](
+You can also `findOne`, `findById`, `update`, etc. For more details check out [the docs](
**Important!** If you opened a separate connection using `mongoose.createConnection()` but attempt to access the model through `mongoose.model('ModelName')` it will not work as expected since it is not hooked up to an active db connection. In this case access your model through the connection you created:
@@ -151,7 +132,7 @@ You can also `findOne`, `findById`, `update`, etc. For more details check out [t
var m = new MyModel; // does not work b/c the default connection object was never connected
-## Embedded Documents
+### Embedded Documents
In the first example snippet, we defined a key in the Schema that looks like:
@@ -187,53 +168,11 @@ Embedded documents enjoy all the same features as your models. Defaults, validat
Mongoose interacts with your embedded documents in arrays _atomically_, out of the box.
-## Middleware
-Middleware is one of the most exciting features about Mongoose. Middleware takes away all the pain of nested callbacks.
-Middleware are defined at the Schema level and are applied for the methods `init` (when a document is initialized with data from MongoDB), `save` (when a document or embedded document is saved).
+### Middleware
-There's two types of middleware:
+See the [docs]( page.
-- Serial
- Serial middleware are defined like:
- .pre(method, function (next, methodArg1, methodArg2, ...) {
- // ...
- })
- They're executed one after the other, when each middleware calls `next`.
- You can also intercept the `method`'s incoming arguments via your middleware -- notice `methodArg1`, `methodArg2`, etc in the `pre` definition above. See section "Intercepting and mutating method arguments" below.
-- Parallel
- Parallel middleware offer more fine-grained flow control, and are defined like:
- .pre(method, true, function (next, done, methodArg1, methodArg2) {
- // ...
- })
- Parallel middleware can `next()` immediately, but the final argument will be called when all the parallel middleware have called `done()`.
-### Error handling
-If any middleware calls `next` or `done` with an `Error` instance, the flow is interrupted, and the error is passed to the function passed as an argument.
-For example:
- schema.pre('save', function (next) {
- // something goes wrong
- next(new Error('something went wrong'));
- });
- // later...
- (err) {
- // err can come from a middleware
- });
-### Intercepting and mutating method arguments
+#### Intercepting and mutating method arguments
You can intercept method arguments via middleware.
@@ -269,7 +208,7 @@ Moreover, you can mutate the incoming `method` arguments so that subsequent midd
-### Schema gotcha
+#### Schema gotcha
`type`, when used in a schema has special meaning within Mongoose. If your schema requires using `type` as a nested property you must use object notation:
@@ -289,42 +228,26 @@ Moreover, you can mutate the incoming `method` arguments so that subsequent midd
-## API docs
-You can find the [Dox]( generated API docs [here](
-## Getting support
-- Google Groups [mailing list](
-- (irc) #mongoosejs on freenode
-- reporting [issues](
-- [10gen](
-## Driver access
+### Driver access
The driver being used defaults to [node-mongodb-native]( and is directly accessible through `YourModel.collection`. **Note**: using the driver directly bypasses all Mongoose power-tools like validation, getters, setters, hooks, etc.
-## Mongoose Plugins
-Take a peek at the [plugins search site]( to see related modules from the community.
-## Contributing to Mongoose
+## API Docs
-### Cloning the repository
+Find the API docs [here](, generated by [dox](
- git clone git://
+## Contributors
-### Guidelines
+View all 80+ [contributors](
-See [contributing](
+## Get Involved
-## Credits
+Stand up and be counted as a [contributor]( to mongoose too!
## License
-Copyright (c) 2010-2012 LearnBoost &lt;;
+Copyright (c) 2010 LearnBoost &lt;;
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

0 comments on commit a234ecd

Please sign in to comment.