Files

Return to Package Diff Home.
Brought to you by Intrinsic.

Package Diff: mongoose @ 3.5.4 .. 3.5.5

History.md

@@ -1,4 +1,17 @@
+3.5.5 / 2013-01-29
+==================
+
+ * updated; driver to 1.2.11
+ * removed; old node < 0.6x shims
+ * fixed; documents with Buffer _ids equality
+ * fixed; MongooseBuffer properly casts numbers
+ * fixed; reopening closed connection on alt host/port #1287
+ * docs; fixed typo in Readme #1298 [rened](https://github.com/rened)
+ * docs; fixed typo in migration docs [Prinzhorn](https://github.com/Prinzhorn)
+ * docs; fixed incorrect annotation in SchemaNumber#min [bilalq](https://github.com/bilalq)
+ * docs; updated
+
3.5.4 / 2013-01-07
==================

lib/connection.js

@@ -4,7 +4,7 @@
var url = require('url')
, utils = require('./utils')
- , EventEmitter = utils.EventEmitter
+ , EventEmitter = require('events').EventEmitter
, driver = global.MONGOOSE_DRIVER_PATH || './drivers/node-mongodb-native'
, Model = require('./model')
, Schema = require('./schema')

lib/document.js

@@ -33,8 +33,6 @@
*/
function Document (obj, fields, skipId) {
- // node <0.4.3 bug
- if (!this._events) this._events = {};
this.setMaxListeners(0);
if ('boolean' === typeof fields) {

lib/drivers/node-mongodb-native/connection.js

@@ -17,6 +17,7 @@
function NativeConnection() {
MongooseConnection.apply(this, arguments);
+ this._listening = false;
};
/*!
@@ -34,14 +35,14 @@
*/
NativeConnection.prototype.doOpen = function (fn) {
- var server
- , self = this;
+ if (this.db) {
+ mute(this);
+ }
- if (!this.db) {
- server = new mongo.Server(this.host, this.port, this.options.server);
+ var server = new mongo.Server(this.host, this.port, this.options.server);
this.db = new mongo.Db(this.name, server, this.options.db);
- }
+ var self = this;
this.db.open(function (err) {
if (err) return fn(err);
fn();
@@ -51,6 +52,11 @@
return this;
};
+
+/*!
+ * Register listeners for important events and bubble appropriately.
+ */
+
function listen (conn) {
if (conn._listening) return;
conn._listening = true;
@@ -83,6 +89,20 @@
})
}
+/*!
+ * Remove listeners registered in `listen`
+ */
+
+function mute (conn) {
+ if (!conn.db) throw new Error('missing db');
+ conn.db.removeAllListeners("close");
+ conn.db.removeAllListeners("error");
+ conn.db.removeAllListeners("timeout");
+ conn.db.removeAllListeners("open");
+ conn.db.removeAllListeners("fullsetup");
+ conn._listening = false;
+}
+
/**
* Opens a connection to a MongoDB ReplicaSet.
*
@@ -94,10 +114,13 @@
*/
NativeConnection.prototype.doOpenSet = function (fn) {
+ if (this.db) {
+ mute(this);
+ }
+
var servers = []
, self = this;
- if (!this.db) {
this.hosts.forEach(function (server) {
var host = server.host || server.ipc;
var port = server.port || 27017;
@@ -110,7 +133,6 @@
this.db.on('fullsetup', function () {
self.emit('fullsetup')
});
- }
this.db.open(function (err) {
if (err) return fn(err);

lib/model.js

@@ -11,7 +11,7 @@
, Schema = require('./schema')
, utils = require('./utils')
, isMongooseObject = utils.isMongooseObject
- , EventEmitter = utils.EventEmitter
+ , EventEmitter = require('events').EventEmitter
, merge = utils.merge
, Promise = require('./promise')
, tick = utils.tick
@@ -795,7 +795,7 @@
Model.schema;
/**
- * Database instance the model uses.
+ * Connection instance the model uses.
*
* @property db
* @receiver Model
@@ -827,11 +827,18 @@
/**
* Removes documents from the collection.
*
+ * ####Example:
+ *
+ * Comment.remove({ title: 'baby born from alien father' }, function (err) {
+ *
+ * });
+ *
* ####Note:
*
* To remove documents without waiting for a response from MongoDB, do not pass a `callback`, then call `exec` on the returned [Query](#query-js):
*
- * Comment.remove({ _id: id }).exec();
+ * var query = Comment.remove({ _id: id });
+ * query.exec();
*
* ####Note:
*
@@ -861,13 +868,33 @@
/**
* Finds documents
*
+ * The `conditions` are cast to their respective SchemaTypes before the command is sent.
+ *
* ####Examples:
*
- * // retrieve only certain keys
- * MyModel.find({ name: /john/i }, 'name friends', function () { })
+ * // named john and at least 18
+ * MyModel.find({ name: 'john', age: { $gte: 18 }});
+ *
+ * // executes immediately, passing results to callback
+ * MyModel.find({ name: 'john', age: { $gte: 18 }}, function (err, docs) {});
+ *
+ * // name LIKE john and only selecting the "name" and "friends" fields, executing immediately
+ * MyModel.find({ name: /john/i }, 'name friends', function (err, docs) { })
+ *
+ * // passing options
+ * MyModel.find({ name: /john/i }, null, { skip: 10 })
+ *
+ * // passing options and executing immediately
+ * MyModel.find({ name: /john/i }, null, { skip: 10 }, function (err, docs) {});
+ *
+ * // executing a query explicitly
+ * var query = MyModel.find({ name: /john/i }, null, { skip: 10 })
+ * query.exec(function (err, docs) {});
*
- * // pass options
- * MyModel.find({ name: /john/i }, null, { skip: 10 } )
+ * // using the promise returned from executing a query
+ * var query = MyModel.find({ name: /john/i }, null, { skip: 10 });
+ * var promise = query.exec();
+ * promise.addBack(function (err, docs) {});
*
* @param {Object} conditions
* @param {Object} [fields] optional fields to select
@@ -875,6 +902,7 @@
* @param {Function} [callback]
* @return {Query}
* @see field selection #query_Query-select
+ * @see promise #promise-js
* @api public
*/
@@ -930,11 +958,30 @@
/**
* Finds a single document by id.
*
- * The `id` is cast to an ObjectId before sending the command.
+ * The `id` is cast based on the Schema before sending the command.
*
* ####Example:
*
- * Adventure.findById(id, callback);
+ * // find adventure by id and execute immediately
+ * Adventure.findById(id, function (err, adventure) {});
+ *
+ * // same as above
+ * Adventure.findById(id).exec(callback);
+ *
+ * // select only the adventures name and length
+ * Adventure.findById(id, 'name length', function (err, adventure) {});
+ *
+ * // same as above
+ * Adventure.findById(id, 'name length').exec(callback);
+ *
+ * // include all properties except for `length`
+ * Adventure.findById(id, '-length').exec(function (err, adventure) {});
+ *
+ * // passing options (in this case return the raw js objects, not mongoose documents by passing `lean`
+ * Adventure.findById(id, 'name', { lean: true }, function (err, doc) {});
+ *
+ * // same as above
+ * Adventure.findById(id, 'name').lean().exec(function (err, doc) {});
*
* @param {ObjectId|HexId} id objectid, or a value that can be casted to one
* @param {Object} [fields] optional fields to select
@@ -942,6 +989,7 @@
* @param {Function} [callback]
* @return {Query}
* @see field selection #query_Query-select
+ * @see lean queries #query_Query-lean
* @api public
*/
@@ -956,7 +1004,26 @@
*
* ####Example:
*
- * Adventure.findOne({ type: 'iphone' }, 'name', { safe: true }, callback);
+ * // find one iphone adventures - iphone adventures??
+ * Adventure.findOne({ type: 'iphone' }, function (err, adventure) {});
+ *
+ * // same as above
+ * Adventure.findOne({ type: 'iphone' }).exec(function (err, adventure) {});
+ *
+ * // select only the adventures name
+ * Adventure.findOne({ type: 'iphone' }, 'name', function (err, adventure) {});
+ *
+ * // same as above
+ * Adventure.findOne({ type: 'iphone' }, 'name').exec(function (err, adventure) {});
+ *
+ * // specify options, in this case lean
+ * Adventure.findOne({ type: 'iphone' }, 'name', { lean: true }, callback);
+ *
+ * // same as above
+ * Adventure.findOne({ type: 'iphone' }, 'name', { lean: true }).exec(callback);
+ *
+ * // chaining findOne queries (same as above)
+ * Adventure.findOne({ type: 'iphone' }).select('name').lean().exec(callback);
*
* @param {Object} conditions
* @param {Object} [fields] optional fields to select
@@ -964,6 +1031,7 @@
* @param {Function} [callback]
* @return {Query}
* @see field selection #query_Query-select
+ * @see lean queries #query_Query-lean
* @api public
*/
@@ -1074,7 +1142,7 @@
*
* Sometimes you need to query for things in mongodb using a JavaScript expression. You can do so via `find({ $where: javascript })`, or you can use the mongoose shortcut method $where via a Query chain or from your mongoose Model.
*
- * Blog.$where('this.comments.length > 5');
+ * Blog.$where('this.comments.length > 5').exec(function (err, docs) {});
*
* @param {String|Function} argument is a javascript string or anonymous function
* @method $where

lib/promise.js

@@ -4,7 +4,7 @@
*/
var util = require('./utils');
-var EventEmitter = util.EventEmitter;
+var EventEmitter = require('events').EventEmitter;
/**
* Promise constructor.
@@ -33,7 +33,7 @@
*
* If `event` is either `error` or `complete` and the event has already been emitted, the`listener` is called immediately and passed the results of the original emitted event.
*
- * @param {Event} event
+ * @param {String} event
* @param {Function} callback
* @return {Promise} this
* @api public
@@ -80,6 +80,8 @@
/**
* Shortcut for emitting the `err` event.
*
+ * If `err` is not instanceof Error, it is cast to Error before rejecting.
+ *
* @api public
* @return {Promise}
*/
@@ -90,9 +92,9 @@
};
/**
- * Shortcut for `.on('complete', fn)`.
+ * Adds a listener to the `complete` (success) event.
*
- * @return {Promise}
+ * @return {Promise} this
* @api public
*/
@@ -101,9 +103,9 @@
};
/**
- * Shortcut for `.on('err', fn)`.
+ * Adds a listener to the `err` (rejected) event.
*
- * @return {Promise}
+ * @return {Promise} this
* @api public
*/
@@ -112,10 +114,13 @@
};
/**
- * Adds a single function that's both a callback and errback.
+ * Adds a single function as both a callback and errback.
+ *
+ * It will be executed with traditional node.js argument position:
+ * function (err, args...) {}
*
* @param {Function} fn
- * @return {Promise}
+ * @return {Promise} this
*/
Promise.prototype.addBack = function (fn) {
@@ -132,10 +137,12 @@
};
/**
- * Sugar for handling cases where you may be resolving to either an error condition or a success condition.
+ * Resolves this promise to an error state if `err` is passed or success state when no `err` is passed.
+ *
+ * `err` will be cast to an Error if not already instanceof Error.
*
- * @param {Error} err optional error or null
- * @param {Object} val value to complete the promise with
+ * @param {Error} [err] error or null
+ * @param {Object} [val] value to complete the promise with
* @api public
*/

lib/schema/buffer.js

@@ -59,7 +59,8 @@
return new MongooseBuffer(value.value(true), [this.path, doc]);
}
- if ('string' === typeof value || Array.isArray(value)) {
+ var type = typeof value;
+ if ('string' == type || 'number' == type || Array.isArray(value)) {
return new MongooseBuffer(value, [this.path, doc]);
}

lib/schema/number.js

@@ -39,7 +39,7 @@
};
/**
- * Sets a maximum number validator.
+ * Sets a minimum number validator.
*
* ####Example:
*

lib/types/buffer.js

@@ -176,6 +176,29 @@
return new Binary(this, subtype);
};
+/**
+ * Determines if this buffer is equals to `other` buffer
+ *
+ * @param {Buffer} other
+ * @return {Boolean}
+ */
+
+MongooseBuffer.prototype.equals = function (other) {
+ if (!Buffer.isBuffer(other)) {
+ return false;
+ }
+
+ if (this.length !== other.length) {
+ return false;
+ }
+
+ for (var i = 0; i < this.length; ++i) {
+ if (this[i] !== other[i]) return false;
+ }
+
+ return true;
+}
+
/*!
* Module exports.
*/

lib/utils.js

@@ -2,8 +2,7 @@
* Module dependencies.
*/
-var EventEmitter = require('events').EventEmitter
- , ReadPref = require('mongodb').ReadPreference
+var ReadPref = require('mongodb').ReadPreference
, ObjectId = require('./types/objectid')
, ms = require('ms')
, sliced = require('sliced')
@@ -111,42 +110,6 @@
return str;
};
-/*!
- * Add `once` to EventEmitter if absent
- *
- * @param {String} event name
- * @param {Function} listener
- * @api private
- */
-
-var Events = EventEmitter;
-
-if (!('once' in EventEmitter.prototype)){
-
- Events = function () {
- EventEmitter.apply(this, arguments);
- };
-
- /*!
- * Inherit from EventEmitter.
- */
-
- Events.prototype.__proto__ = EventEmitter.prototype;
-
- /*!
- * Add `once`.
- */
-
- Events.prototype.once = function (type, listener) {
- var self = this;
- self.on(type, function g(){
- self.removeListener(type, g);
- listener.apply(this, arguments);
- });
- };
-}
-exports.EventEmitter = Events;
-
/**
* Determines if `a` and `b` are deep equal.
*

package.json

@@ -1,12 +1,12 @@
{
"name": "mongoose"
, "description": "Mongoose MongoDB ODM"
- , "version": "3.5.4"
+ , "version": "3.5.5"
, "author": "Guillermo Rauch <guillermo@learnboost.com>"
, "keywords": ["mongodb", "mongoose", "orm", "data", "datastore", "nosql", "odm", "sql", "db", "database"]
, "dependencies": {
"hooks": "0.2.1"
- , "mongodb": "1.2.8"
+ , "mongodb": "1.2.11"
, "ms": "0.1.0"
, "sliced": "0.0.3"
, "muri": "0.1.0"

README.md

@@ -86,7 +86,7 @@
* [Methods](http://mongoosejs.com/docs/guide.html#methods) definition
* [Statics](http://mongoosejs.com/docs/guide.html#statics) definition
* [Plugins](http://mongoosejs.com/docs/plugins.html)
-* [psuedo-JOINs](http://mongoosejs.com/docs/populate.html)
+* [pseudo-JOINs](http://mongoosejs.com/docs/populate.html)
The following example shows some of these features:

.travis.yml

@@ -1,6 +1,5 @@
language: node_js
node_js:
- - 0.4
- 0.6
- 0.8
services: