First,weneedtodefineaconnection.Ifyourappusesonlyonedatabase,youshoulduse`mongose.connect`. If you need to create additional connections, use `mongoose.createConnection`.
Both`connect` and `createConnection` take a `mongodb://` URI, or the parameters `host, database, port, options`.
Onceconnected,the`open` event is fired on the `Connection` instance. If you're using `mongoose.connect`, the `Connection` is `mongoose.connection`. Otherwise, `mongoose.createConnection` return value is a `Connection`.
**Important!**Ifyouopenedaseparateconnectionusing`mongoose.createConnection()` but attempt to access the model through `mongoose.model('ModelName')`itwillnotworkasexpectedsinceitisnothookeduptoanactivedbconnection.Inthiscaseaccessyourmodelthroughtheconnectionyoucreated:
Moreover,youcanmutatetheincoming`method` arguments so that subsequent middleware see different values for those arguments. To do so, just pass the new values to `next`:
`type`, when used in a schema has special meaning within Mongoose. If your schema requires using `type`asanestedpropertyyoumustuseobjectnotation:
newSchema({
broken:{type:Boolean}
,asset:{
name:String
,type:String// uh oh, it broke. asset will be interpreted as String
}
});
newSchema({
works:{type:Boolean}
,asset:{
name:String
,type:{type:String}// works. asset is an object with a type property
}
});
###Driveraccess
Thedriverbeinguseddefaultsto[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.
##APIDocs
FindtheAPIdocs[here](http://mongoosejs.com/docs/api.html), generated by [dox](http://github.com/visionmedia/dox).