From fb0de2f692c4eeb38833b9946769068c3f79efbe Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Thu, 19 Apr 2012 10:57:14 -0700 Subject: [PATCH 1/4] include bson library and use its BinaryParser --- lib/plugins/useTimestamps.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plugins/useTimestamps.js b/lib/plugins/useTimestamps.js index d7bbcef..b4ece29 100644 --- a/lib/plugins/useTimestamps.js +++ b/lib/plugins/useTimestamps.js @@ -1,6 +1,6 @@ var mongoose = require('mongoose') , ObjectID = mongoose.ObjectID - , BinaryParser = mongoose.mongo.BinaryParser; + , BinaryParser = require('bson').BinaryParser; exports.useTimestamps = function (schema, options) { if (schema.path('_id')) { diff --git a/package.json b/package.json index 4e47092..f224276 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ , "description": "More types for mongoose" , "version": "1.0.3" , "author": "Brian Noguchi" -, "dependencies": { "mongoose": ">= 1.0.16"} +, "dependencies": { "mongoose": ">= 1.0.16", "bson": ">= 0.0.4" } , "keywords": [ "mongoose", "mongo", "mongodb", "types" ] , "scripts": { "test": "make test" } , "engines": { "node": ">= 0.1.101" } From 3faca488a28d77460425f231c9636c0184ab30b5 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Wed, 25 Apr 2012 18:09:44 -0700 Subject: [PATCH 2/4] always write createdAt --- lib/plugins/useTimestamps.js | 44 ++++++++++-------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/lib/plugins/useTimestamps.js b/lib/plugins/useTimestamps.js index b4ece29..73321e0 100644 --- a/lib/plugins/useTimestamps.js +++ b/lib/plugins/useTimestamps.js @@ -3,36 +3,16 @@ var mongoose = require('mongoose') , BinaryParser = require('bson').BinaryParser; exports.useTimestamps = function (schema, options) { - if (schema.path('_id')) { - schema.add({ - updatedAt: Date - }); - schema.virtual('createdAt') - .get( function () { - if (this._createdAt) return this._createdAt; - var unixtime = BinaryParser.decodeInt(this._id.id.slice(0, 4), 32, true, true); - return this._createdAt = new Date(unixtime * 1000); - }); - schema.pre('save', function (next) { - if (this.isNew) { - this.updatedAt = this.createdAt; - } else { - this.updatedAt = new Date; - } - next(); - }); - } else { - schema.add({ - createdAt: Date - , updatedAt: Date - }); - schema.pre('save', function (next) { - if (!this.createdAt) { - this.createdAt = this.updatedAt = new Date; - } else { - this.updatedAt = new Date; - } - next(); - }); - } + schema.add({ + createdAt: Date + , updatedAt: Date + }); + schema.pre('save', function (next) { + if (!this.createdAt) { + this.createdAt = this.updatedAt = new Date; + } else { + this.updatedAt = new Date; + } + next(); + }); }; From 5c5488f6ed2123472d95a8da2a5bdfff906e4964 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Wed, 25 Apr 2012 18:12:54 -0700 Subject: [PATCH 3/4] update version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f224276..1b9a5ac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mongoose-types" , "description": "More types for mongoose" -, "version": "1.0.3" +, "version": "1.0.3-2" , "author": "Brian Noguchi" , "dependencies": { "mongoose": ">= 1.0.16", "bson": ">= 0.0.4" } , "keywords": [ "mongoose", "mongo", "mongodb", "types" ] From 1078b9ac9e7433ab8915ce12a7569e6d40d3a81c Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Fri, 27 Apr 2012 00:12:56 -0700 Subject: [PATCH 4/4] since we're always creating createdAt, we don't need the BinaryParser or bson package --- lib/plugins/useTimestamps.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plugins/useTimestamps.js b/lib/plugins/useTimestamps.js index 73321e0..afd7676 100644 --- a/lib/plugins/useTimestamps.js +++ b/lib/plugins/useTimestamps.js @@ -1,6 +1,6 @@ var mongoose = require('mongoose') , ObjectID = mongoose.ObjectID - , BinaryParser = require('bson').BinaryParser; + //, BinaryParser = require('bson').BinaryParser; exports.useTimestamps = function (schema, options) { schema.add({ diff --git a/package.json b/package.json index 1b9a5ac..4857a5e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ , "description": "More types for mongoose" , "version": "1.0.3-2" , "author": "Brian Noguchi" -, "dependencies": { "mongoose": ">= 1.0.16", "bson": ">= 0.0.4" } +, "dependencies": { "mongoose": ">= 1.0.16" } , "keywords": [ "mongoose", "mongo", "mongodb", "types" ] , "scripts": { "test": "make test" } , "engines": { "node": ">= 0.1.101" }