3.5.0 / 2012-12-10
==================
* added; paths to CastErrors #1239
* added; support for mongodb connection string spec #1187
* added; post validate event
* added; Schema#get (to retrieve schema options)
* added; VersionError #1071
* update; driver to 1.2.3
* fixed; stackoverflow in setter #1234
* fixed; utils.isObject()
* fixed; do not clobber user specified driver writeConern #1227
* fixed; always pass current document to post hooks
* fixed; throw error when user attempts to overwrite a model
* fixed; connection.model only caches on connection #1209
* fixed; respect conn.model() creation when matching global model exists #1209
* fixed; passing model name + collection name now always honors collection name
* fixed; setting virtual field to an empty object #1154
* fixed; subclassed MongooseErrors exposure, now available in mongoose.Error.xxxx
* docs; add collection option to schema api docs #1222
* docs; NOTE about db safe options
* docs; add post hooks docs
* docs; connection string options
* docs; middleware is not executed with Model.remove #1241
* docs; {g,s}etter introspection #777
* docs; update validation docs
* docs; add link to plugins page
* docs; clarify error returned by unique indexes #1225
* docs; more detail about disabling autoIndex behavior
* docs; add homepage section to package (npm docs mongoose)
* docs; more detail around collection name pluralization #1193
* website; add .important css
* website; update models page
* website; update getting started
* website; update quick start
Added
=============
CastErrors now include the path containing the bad value.
Movies.findById("", function (err) {
console.log(err) // Cast to ObjectId failed for value "" at path "_id"
console.log(err.path) // _id
})
Mongoose now supports the full MongoDB connection string spec (
http://www.mongodb.org/display/DOCS/Connections ). Among other things, this allows us to now pass many driver options in the connection string instead of through a separate options object.
// old
mongoose.connect('mongodb://user:pwd@localhost:12345/dbname', { db: { w: 1, wtimeoutMS: 2000 }})
// new
mongoose.connect('mongodb://user:pwd@localhost:12345/dbname?w=1&wtimeoutMS=2000')
There is now a post validate event to make things more consistent between init, validate, save, and remove. All four of these "post" events also now receive the document on which the event was fired. Previously post init did not receive the document.
console.log('this was removed:', doc);
})
Schemas now have a "get" method to retrieve option values. Previously they were only accessible through Schema#set(key).
Versioning errors are now instanceof mongoose.Error.VersionError, which is still instanceof Error. This makes for more foolproof detection of these errors versus just checking the error message string.
doc.save(function (err) {
// old
if ('No matching document found.' == err.message) ...
// new
if (err instanceof VersionError) ...
})
Changed / Fixed
=============
* fixed; do not clobber user specified driver writeConcern #1227
Schemas no longer have their "safe" option set by default, the value is now set at the connection level. This causes no behavior change other than now allowing us to pass writeConcern options when connecting and having them honored instead of being overwritten by the schemas option. We may continue to set our safe options at the schema level as before.
* fixed; throw error when user attempts to overwrite a model
Previously, if we attempted to overwrite a model by passing the same model name with a new schema to mongoose.model or connection.model, the previously compiled model would be returned, and the programming error would be swallowed. Attempting to overwrite a previously compiled model is now properly treated as an error.
* fixed; connection.model only caches on connection #1209
Previously, calling connection.model with a new model name and schema would compile the model and cache it globally (accessible to mongoose.model). This caused problems when users required different models on different connections with the same model name. Models compiled for a given connection are now only cached on that connection, not globally.
mongoose.model('A', schemaA);
var db = mongoose.createConnection(..);
var model = db.model('A', schemaB);
// old behavior would return model compiled from schemaA
// new behavior in 3.5.0 returns a new model compiled from schemaB and cached on connection only
* fixed; passing model name + collection name now always honors collection name
Previously, when passing just the name of a precompiled model and a collection name it was implied that a model would be returned that utilized the collection name. This feature was broken, the model was being returned from the cache with no changes made for the collection name. This is now fixed. A subclassed, one-off (non-cached) model that honors the collection name is now returned.
* fixed; setting virtual field to an empty object #1154
Previously, virtual setters were not properly triggered when set to an empty object. Now they are.
schema.virtual('fullname').set(function (val) {
console.log(val) // {}
})
...
doc.fullname = {};
* fixed/reorganized; subclassed MongooseErrors exposure, now available in mongoose.Error.xxxx
All mongoose custom error types are now accessible through mongoose.Error.xxxx. mongoose.Error is the class from which all mongoose error subclasses are derived.
Resolved issues
=============
--
Aaron