Permalink
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 README.md
View
135 README.md
@@ -2,52 +2,33 @@
Mongoose is a [MongoDB](http://www.mongodb.org/) 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
[mongoosejs.com](http://mongoosejs.com/)
## Try it live
<a href="https://runnable.com/#learnboost/mongoose/code.js/launch" target="_blank"><img src="https://runnable.com/external/styles/assets/runnablebtn.png" style="width:67px;height:25px;"></a>
-## Installation
-The recommended way is through the excellent [NPM](http://www.npmjs.org/):
+## Support
- $ npm install mongoose
+ - [help forum](http://groups.google.com/group/mongoose-orm)
+ - [bug reports](https://github.com/learnboost/mongoose/issues/)
+ - [10gen support](http://www.mongodb.org/display/DOCS/Technical+Support)
+ - (irc) #mongoosejs on freenode
-Otherwise, you can check it in your repository and then expose it:
+## Installation
+
+First install [node.js](http://nodejs.org/) and [mongodb](http://www.mongodb.org/downloads).
- $ git clone git://github.com/LearnBoost/mongoose.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](http://plugins.mongoosejs.com/) 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](http://mongoosejs.com/docs/queries.html).
+You can also `findOne`, `findById`, `update`, etc. For more details check out [the docs](http://mongoosejs.com/docs/queries.html).
**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;
m.save() // 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](http://mongoosejs.com/docs/middleware.html) 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...
-
- myModel.save(function (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
next();
})
-### 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](http://github.com/visionmedia/dox) generated API docs [here](http://mongoosejs.com/docs/api.html).
-
-## Getting support
-
-- Google Groups [mailing list](http://groups.google.com/group/mongoose-orm)
-- (irc) #mongoosejs on freenode
-- reporting [issues](https://github.com/learnboost/mongoose/issues/)
-- [10gen](http://www.mongodb.org/display/DOCS/Technical+Support)
-
-## Driver access
+### Driver access
The driver being used defaults to [node-mongodb-native](https://github.com/mongodb/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](http://plugins.mongoosejs.com/) to see related modules from the community.
-
-## Contributing to Mongoose
+## API Docs
-### Cloning the repository
+Find the API docs [here](http://mongoosejs.com/docs/api.html), generated by [dox](http://github.com/visionmedia/dox).
- git clone git://github.com/LearnBoost/mongoose.git
+## Contributors
-### Guidelines
+View all 80+ [contributors](https://github.com/learnboost/mongoose/graphs/contributors).
-See [contributing](http://mongoosejs.com/docs/contributing.html).
+## Get Involved
-## Credits
+Stand up and be counted as a [contributor](https://github.com/LearnBoost/mongoose/blob/master/CONTRIBUTING.md) to mongoose too!
-[contributors](https://github.com/learnboost/mongoose/graphs/contributors)
## License
-Copyright (c) 2010-2012 LearnBoost &lt;dev@learnboost.com&gt;
+Copyright (c) 2010 LearnBoost &lt;dev@learnboost.com&gt;
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.