diff --git a/packages/mongo/collection.js b/packages/mongo/collection.js index 6a1a6906a4..9793e4a57d 100644 --- a/packages/mongo/collection.js +++ b/packages/mongo/collection.js @@ -429,12 +429,18 @@ Mongo.Collection.prototype.insert = function insert(doc, callback) { throw new Error("insert requires an argument"); } - // Shallow-copy the document and possibly generate an ID - doc = _.extend({}, doc); + // Make a shallow clone of the document, preserving its prototype. + doc = Object.create( + Object.getPrototypeOf(doc), + Object.getOwnPropertyDescriptors(doc) + ); if ('_id' in doc) { - if (!doc._id || !(typeof doc._id === 'string' || doc._id instanceof Mongo.ObjectID)) { - throw new Error("Meteor requires document _id fields to be non-empty strings or ObjectIDs"); + if (! doc._id || + ! (typeof doc._id === 'string' || + doc._id instanceof Mongo.ObjectID)) { + throw new Error( + "Meteor requires document _id fields to be non-empty strings or ObjectIDs"); } } else { let generateId = true; diff --git a/packages/mongo/mongo_livedata_tests.js b/packages/mongo/mongo_livedata_tests.js index 932b98caca..98ef9955a2 100644 --- a/packages/mongo/mongo_livedata_tests.js +++ b/packages/mongo/mongo_livedata_tests.js @@ -1507,7 +1507,9 @@ testAsyncMulti('mongo-livedata - document with a custom type, ' + idGeneration, Meteor.call('createInsecureCollection', this.collectionName, collectionOptions); Meteor.subscribe('c-' + this.collectionName, expect()); } - }, function (test, expect) { + }, + + function (test, expect) { var self = this; self.coll = new Mongo.Collection(this.collectionName, collectionOptions); var docId; @@ -1525,13 +1527,17 @@ testAsyncMulti('mongo-livedata - document with a custom type, ' + idGeneration, test.isTrue(inColl); inColl && test.equal(inColl.d.speak(), "woof"); })); - }, function (test, expect) { + }, + + function (test, expect) { var self = this; self.coll.insert(new Dog("rover", "orange"), expect(function (err, id) { test.isTrue(err); test.isFalse(id); })); - }, function (test, expect) { + }, + + function (test, expect) { var self = this; self.coll.update( self.docId, new Dog("rover", "orange"), expect(function (err) { diff --git a/packages/mongo/package.js b/packages/mongo/package.js index 85c5a094fd..a765a8052f 100644 --- a/packages/mongo/package.js +++ b/packages/mongo/package.js @@ -9,7 +9,7 @@ Package.describe({ summary: "Adaptor for using MongoDB and Minimongo over DDP", - version: '1.2.2' + version: '1.2.3' }); Npm.depends({