Skip to content

Instantly share code, notes, and snippets.

@iolo
Created July 28, 2013 06:50
Show Gist options
  • Save iolo/6097711 to your computer and use it in GitHub Desktop.
Save iolo/6097711 to your computer and use it in GitHub Desktop.
diff -uNr node_modules/mongoose-3.6.14/History.md node_modules/mongoose/History.md
--- node_modules/mongoose-3.6.14/History.md 2013-07-06 07:16:15.000000000 +0900
+++ node_modules/mongoose/History.md 2013-07-17 04:07:52.000000000 +0900
@@ -1,4 +1,13 @@
+3.6.15 / 2013-07-16
+==================
+
+ * added; mongos failover support #1037
+ * updated; make schematype return vals return self #1580
+ * docs; add note to model.update #571
+ * docs; document third param to document.save callback #1536
+ * tests; tweek mongos test timeout
+
3.6.14 / 2013-07-05
===================
diff -uNr node_modules/mongoose-3.6.14/lib/drivers/node-mongodb-native/connection.js node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js
--- node_modules/mongoose-3.6.14/lib/drivers/node-mongodb-native/connection.js 2013-07-06 07:14:12.000000000 +0900
+++ node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js 2013-07-17 03:48:10.000000000 +0900
@@ -4,7 +4,9 @@
var MongooseConnection = require('../../connection')
, mongo = require('mongodb')
+ , Db = mongo.Db
, Server = mongo.Server
+ , Mongos = mongo.Mongos
, STATES = require('../../connectionstate')
, ReplSetServers = mongo.ReplSetServers;
@@ -39,8 +41,8 @@
mute(this);
}
- var server = new mongo.Server(this.host, this.port, this.options.server);
- this.db = new mongo.Db(this.name, server, this.options.db);
+ var server = new Server(this.host, this.port, this.options.server);
+ this.db = new Db(this.name, server, this.options.db);
var self = this;
this.db.open(function (err) {
@@ -123,11 +125,13 @@
this.hosts.forEach(function (server) {
var host = server.host || server.ipc;
var port = server.port || 27017;
- servers.push(new mongo.Server(host, port, self.options.server));
+ servers.push(new Server(host, port, self.options.server));
})
- var server = new ReplSetServers(servers, this.options.replset);
- this.db = new mongo.Db(this.name, server, this.options.db);
+ var server = this.options.mongos
+ ? new Mongos(servers, this.options.mongos)
+ : new ReplSetServers(servers, this.options.replset);
+ this.db = new Db(this.name, server, this.options.db);
this.db.on('fullsetup', function () {
self.emit('fullsetup')
diff -uNr node_modules/mongoose-3.6.14/lib/model.js node_modules/mongoose/lib/model.js
--- node_modules/mongoose-3.6.14/lib/model.js 2013-07-06 07:14:12.000000000 +0900
+++ node_modules/mongoose/lib/model.js 2013-07-17 04:00:46.000000000 +0900
@@ -136,10 +136,12 @@
* ####Example:
*
* product.sold = Date.now();
- * product.save(function (err, product) {
+ * product.save(function (err, product, numberAffected) {
* if (err) ..
* })
*
+ * The callback will receive three parameters, `err` if an error occurred, `product` which is the saved `product`, and `numberAffected` which will be 1 when the document was found and updated in the database, otherwise 0.
+ *
* The `fn` callback is optional. If no `fn` is passed and validation fails, the validation error will be emitted on the connection used to create this model.
*
* var db = mongoose.createConnection(..);
@@ -1449,6 +1451,10 @@
*
* ####Note:
*
+ * Be careful to not use an existing model instance for the update clause (this won't work and can cause weird behavior like infinite loops). Also, ensure that the update clause does not have an _id property, which causes Mongo to return a "Mod on _id not allowed" error.
+ *
+ * ####Note:
+ *
* To update documents without waiting for a response from MongoDB, do not pass a `callback`, then call `exec` on the returned [Query](#query-js):
*
* Comment.update({ _id: id }, { $set: { text: 'changed' }}).exec();
diff -uNr node_modules/mongoose-3.6.14/lib/schema/number.js node_modules/mongoose/lib/schema/number.js
--- node_modules/mongoose-3.6.14/lib/schema/number.js 2013-05-25 01:54:09.000000000 +0900
+++ node_modules/mongoose/lib/schema/number.js 2013-07-17 03:13:42.000000000 +0900
@@ -55,6 +55,7 @@
* })
*
* @param {Number} value minimum number
+ * @return {SchemaType} this
* @api public
*/
@@ -89,6 +90,7 @@
* })
*
* @param {Number} maximum number
+ * @return {SchemaType} this
* @api public
*/
diff -uNr node_modules/mongoose-3.6.14/lib/schema/objectid.js node_modules/mongoose/lib/schema/objectid.js
--- node_modules/mongoose-3.6.14/lib/schema/objectid.js 2013-07-06 07:14:12.000000000 +0900
+++ node_modules/mongoose/lib/schema/objectid.js 2013-07-17 04:00:46.000000000 +0900
@@ -29,6 +29,22 @@
ObjectId.prototype.__proto__ = SchemaType.prototype;
/**
+ * Adds an auto-generated ObjectId default if turnOn is true.
+ * @param {Boolean} turnOn auto generated ObjectId defaults
+ * @api public
+ * @return {SchemaType} this
+ */
+
+ObjectId.prototype.auto = function (turnOn) {
+ if (turnOn) {
+ this.default(defaultId);
+ this.set(resetId)
+ }
+
+ return this;
+};
+
+/**
* Check required
*
* @api private
@@ -150,19 +166,6 @@
}
};
-/**
- * Adds an auto-generated ObjectId default if turnOn is true.
- * @param {Boolean} turnOn auto generated ObjectId defaults
- * @api public
- */
-
-ObjectId.prototype.auto = function (turnOn) {
- if (turnOn) {
- this.default(defaultId);
- this.set(resetId)
- }
-};
-
/*!
* ignore
*/
diff -uNr node_modules/mongoose-3.6.14/lib/schema/string.js node_modules/mongoose/lib/schema/string.js
--- node_modules/mongoose-3.6.14/lib/schema/string.js 2013-05-25 01:54:09.000000000 +0900
+++ node_modules/mongoose/lib/schema/string.js 2013-07-17 03:13:42.000000000 +0900
@@ -45,11 +45,13 @@
* })
*
* @param {String} [args...] enumeration values
+ * @return {SchemaType} this
* @api public
*/
SchemaString.prototype.enum = function () {
var len = arguments.length;
+
if (!len || undefined === arguments[0] || false === arguments[0]) {
if (this.enumValidator){
this.enumValidator = false;
@@ -57,7 +59,7 @@
return v[1] != 'enum';
});
}
- return;
+ return this;
}
for (var i = 0; i < len; i++) {
@@ -73,6 +75,8 @@
};
this.validators.push([this.enumValidator, 'enum']);
}
+
+ return this;
};
/**
@@ -86,6 +90,7 @@
* console.log(m.email) // someemail@example.com
*
* @api public
+ * @return {SchemaType} this
*/
SchemaString.prototype.lowercase = function () {
@@ -107,6 +112,7 @@
* console.log(m.caps) // AN EXAMPLE
*
* @api public
+ * @return {SchemaType} this
*/
SchemaString.prototype.uppercase = function () {
@@ -132,6 +138,7 @@
* console.log(m.name.length) // 9
*
* @api public
+ * @return {SchemaType} this
*/
SchemaString.prototype.trim = function () {
@@ -161,6 +168,7 @@
* })
*
* @param {RegExp} regExp regular expression to test against
+ * @return {SchemaType} this
* @api public
*/
@@ -170,6 +178,8 @@
? regExp.test(v)
: true
}, 'regexp']);
+
+ return this;
};
/**
diff -uNr node_modules/mongoose-3.6.14/lib/schematype.js node_modules/mongoose/lib/schematype.js
--- node_modules/mongoose-3.6.14/lib/schematype.js 2013-07-06 07:14:12.000000000 +0900
+++ node_modules/mongoose/lib/schematype.js 2013-07-17 04:00:46.000000000 +0900
@@ -364,6 +364,7 @@
*
* @param {RegExp|Function|Object} obj validator
* @param {String} [error] optional error message
+ * @return {SchemaType} this
* @api public
*/
@@ -527,11 +528,13 @@
* T.find().select('-x').exec(callback);
*
* @param {Boolean} val
+ * @return {SchemaType} this
* @api public
*/
SchemaType.prototype.select = function select (val) {
this.selected = !! val;
+ return this;
}
/**
Binary files node_modules/mongoose-3.6.14/node_modules/mongodb/node_modules/bson/build/Release/bson.node and node_modules/mongoose/node_modules/mongodb/node_modules/bson/build/Release/bson.node differ
Binary files node_modules/mongoose-3.6.14/node_modules/mongodb/node_modules/kerberos/build/Release/kerberos.node and node_modules/mongoose/node_modules/mongodb/node_modules/kerberos/build/Release/kerberos.node differ
diff -uNr node_modules/mongoose-3.6.14/node_modules/mongodb/node_modules/kerberos/package.json node_modules/mongoose/node_modules/mongodb/node_modules/kerberos/package.json
--- node_modules/mongoose-3.6.14/node_modules/mongodb/node_modules/kerberos/package.json 2013-07-28 15:40:00.000000000 +0900
+++ node_modules/mongoose/node_modules/mongodb/node_modules/kerberos/package.json 2013-07-28 15:41:37.000000000 +0900
@@ -30,9 +30,5 @@
"url": "https://github.com/christkv/kerberos/issues"
},
"_id": "kerberos@0.0.3",
- "dist": {
- "shasum": "68a91ac749970aab79ac0e73330614799d8315ff"
- },
- "_from": "kerberos@0.0.3",
- "_resolved": "https://registry.npmjs.org/kerberos/-/kerberos-0.0.3.tgz"
+ "_from": "kerberos@0.0.3"
}
diff -uNr node_modules/mongoose-3.6.14/package.json node_modules/mongoose/package.json
--- node_modules/mongoose-3.6.14/package.json 2013-07-28 15:39:41.000000000 +0900
+++ node_modules/mongoose/package.json 2013-07-28 15:41:18.000000000 +0900
@@ -1,7 +1,7 @@
{
"name": "mongoose",
"description": "Elegant MongoDB object modeling for Node.js",
- "version": "3.6.14",
+ "version": "3.6.15",
"author": {
"name": "Guillermo Rauch",
"email": "guillermo@learnboost.com"
@@ -60,10 +60,10 @@
"homepage": "http://mongoosejs.com",
"readme": "## What's Mongoose?\n\nMongoose is a [MongoDB](http://www.mongodb.org/) object modeling tool designed to work in an asynchronous environment.\n\n## Documentation\n\n[mongoosejs.com](http://mongoosejs.com/)\n\n## Try it live\n<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>\n\n## Support\n\n - [Stack Overflow](http://stackoverflow.com/questions/tagged/mongoose)\n - [bug reports](https://github.com/learnboost/mongoose/issues/)\n - [help forum](http://groups.google.com/group/mongoose-orm)\n - [10gen support](http://www.mongodb.org/display/DOCS/Technical+Support)\n - (irc) #mongoosejs on freenode\n\n## Installation\n\nFirst install [node.js](http://nodejs.org/) and [mongodb](http://www.mongodb.org/downloads).\n\n $ npm install mongoose\n\n## Plugins\n\nCheck out the [plugins search site](http://plugins.mongoosejs.com/) to see hundreds of related modules from the community.\n\n## Contributors\n\nView all 90+ [contributors](https://github.com/learnboost/mongoose/graphs/contributors).\n\n## Get Involved\n\nStand up and be counted as a [contributor](https://github.com/LearnBoost/mongoose/blob/master/CONTRIBUTING.md) too!\n\n## Overview\n\n### Connecting to MongoDB\n\nFirst, 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`.\n\nBoth `connect` and `createConnection` take a `mongodb://` URI, or the parameters `host, database, port, options`.\n\n var mongoose = require('mongoose');\n\n mongoose.connect('mongodb://localhost/my_database');\n\nOnce connected, 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`.\n\n**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.\n\n### Defining a Model\n\nModels are defined through the `Schema` interface. \n\n var Schema = mongoose.Schema\n , ObjectId = Schema.ObjectId;\n\n var BlogPost = new Schema({\n author : ObjectId\n , title : String\n , body : String\n , date : Date\n });\n\nAside from defining the structure of your documents and the types of data you're storing, a Schema handles the definition of:\n\n* [Validators](http://mongoosejs.com/docs/validation.html) (async and sync)\n* [Defaults](http://mongoosejs.com/docs/api.html#schematype_SchemaType-default)\n* [Getters](http://mongoosejs.com/docs/api.html#schematype_SchemaType-get)\n* [Setters](http://mongoosejs.com/docs/api.html#schematype_SchemaType-set)\n* [Indexes](http://mongoosejs.com/docs/guide.html#indexes)\n* [Middleware](http://mongoosejs.com/docs/middleware.html)\n* [Methods](http://mongoosejs.com/docs/guide.html#methods) definition\n* [Statics](http://mongoosejs.com/docs/guide.html#statics) definition\n* [Plugins](http://mongoosejs.com/docs/plugins.html)\n* [pseudo-JOINs](http://mongoosejs.com/docs/populate.html)\n\nThe following example shows some of these features:\n\n var Comment = new Schema({\n name : { type: String, default: 'hahaha' }\n , age : { type: Number, min: 18, index: true }\n , bio : { type: String, match: /[a-z]/ }\n , date : { type: Date, default: Date.now }\n , buff : Buffer\n });\n\n // a setter\n Comment.path('name').set(function (v) {\n return capitalize(v);\n });\n\n // middleware\n Comment.pre('save', function (next) {\n notify(this.get('email'));\n next();\n });\n\nTake a look at the example in `examples/schema.js` for an end-to-end example of a typical setup.\n\n### Accessing a Model\n\nOnce we define a model through `mongoose.model('ModelName', mySchema)`, we can access it through the same function\n\n var myModel = mongoose.model('ModelName');\n\nOr just do it all at once\n\n var MyModel = mongoose.model('ModelName', mySchema);\n\nWe can then instantiate it, and save it:\n\n var instance = new MyModel();\n instance.my.key = 'hello';\n instance.save(function (err) {\n //\n });\n\nOr we can find documents from the same collection\n\n MyModel.find({}, function (err, docs) {\n // docs.forEach\n });\n\nYou can also `findOne`, `findById`, `update`, etc. For more details check out [the docs](http://mongoosejs.com/docs/queries.html).\n\n**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:\n\n var conn = mongoose.createConnection('your connection string');\n var MyModel = conn.model('ModelName', schema);\n var m = new MyModel;\n m.save() // works\n\n vs\n\n var conn = mongoose.createConnection('your connection string');\n var MyModel = mongoose.model('ModelName', schema);\n var m = new MyModel;\n m.save() // does not work b/c the default connection object was never connected\n\n### Embedded Documents\n\nIn the first example snippet, we defined a key in the Schema that looks like:\n\n comments: [Comments]\n\nWhere `Comments` is a `Schema` we created. This means that creating embedded documents is as simple as:\n\n // retrieve my model\n var BlogPost = mongoose.model('BlogPost');\n\n // create a blog post\n var post = new BlogPost();\n\n // create a comment\n post.comments.push({ title: 'My comment' });\n\n post.save(function (err) {\n if (!err) console.log('Success!');\n });\n\nThe same goes for removing them:\n\n BlogPost.findById(myId, function (err, post) {\n if (!err) {\n post.comments[0].remove();\n post.save(function (err) {\n // do something\n });\n }\n });\n\nEmbedded documents enjoy all the same features as your models. Defaults, validators, middleware. Whenever an error occurs, it's bubbled to the `save()` error callback, so error handling is a snap!\n\nMongoose interacts with your embedded documents in arrays _atomically_, out of the box.\n\n### Middleware\n\nSee the [docs](http://mongoosejs.com/docs/middleware.html) page.\n\n#### Intercepting and mutating method arguments\n\nYou can intercept method arguments via middleware.\n\nFor example, this would allow you to broadcast changes about your Documents every time someone `set`s a path in your Document to a new value:\n\n schema.pre('set', function (next, path, val, typel) {\n // `this` is the current Document\n this.emit('set', path, val);\n\n // Pass control to the next pre\n next();\n });\n\nMoreover, you can mutate the incoming `method` arguments so that subsequent middleware see different values for those arguments. To do so, just pass the new values to `next`:\n\n .pre(method, function firstPre (next, methodArg1, methodArg2) {\n // Mutate methodArg1\n next(\"altered-\" + methodArg1.toString(), methodArg2);\n })\n\n // pre declaration is chainable\n .pre(method, function secondPre (next, methodArg1, methodArg2) {\n console.log(methodArg1);\n // => 'altered-originalValOfMethodArg1' \n \n console.log(methodArg2);\n // => 'originalValOfMethodArg2' \n \n // Passing no arguments to `next` automatically passes along the current argument values\n // i.e., the following `next()` is equivalent to `next(methodArg1, methodArg2)`\n // and also equivalent to, with the example method arg \n // values, `next('altered-originalValOfMethodArg1', 'originalValOfMethodArg2')`\n next();\n })\n\n#### Schema gotcha\n\n`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:\n\n new Schema({\n broken: { type: Boolean }\n , asset : {\n name: String\n , type: String // uh oh, it broke. asset will be interpreted as String\n }\n });\n\n new Schema({\n works: { type: Boolean }\n , asset : {\n name: String\n , type: { type: String } // works. asset is an object with a type property\n }\n });\n\n### Driver access\n\nThe 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.\n\n## API Docs\n\nFind the API docs [here](http://mongoosejs.com/docs/api.html), generated by [dox](http://github.com/visionmedia/dox).\n\n## License\n\nCopyright (c) 2010 LearnBoost &lt;dev@learnboost.com&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"readmeFilename": "README.md",
- "_id": "mongoose@3.6.14",
+ "_id": "mongoose@3.6.15",
"dist": {
- "shasum": "acf28354ba4f792ded931ccd0dfe038a65757832"
+ "shasum": "272f1575da3b48ec31467abdf15baa61854ba5f1"
},
- "_from": "mongoose@=3.6.14",
- "_resolved": "https://registry.npmjs.org/mongoose/-/mongoose-3.6.14.tgz"
+ "_from": "mongoose@=3.6.15",
+ "_resolved": "https://registry.npmjs.org/mongoose/-/mongoose-3.6.15.tgz"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment