Mongoose plugin to save document data versions. Documents are saved to a "versioned" document collection before saving original documents and kept for later use.
it('should version model with an array', function(done) {
var childSchema = new Schema({ name: 'string' });
var testSchema = new Schema({ name : String, subdoc: [childSchema] });
testSchema.plugin(version, { collection : 'should_allow_array_content' });
var Test = mongoose.model('should_allow_array', testSchema);
var test = new Test();
test.name = 'franz';
test.subdoc.push(new childSchema({name:'subdoc'}));
// Save one generates a version
test.save(function(err) {
assert.ifError(err);
test.name = 'hugo';
// Save two generates a version
test.save(function(err) {
assert.ifError(err);
Test.VersionedModel.findOne({ refId : test._id}, function(err, versionedModel) {
assert.ifError(err);
assert.ok(versionedModel);
// expected versions in array: 2
assert.equal(versionedModel.versions.length, 2);
done();
});
});
});
});
I get:
1) version should version model with an array:
TypeError: Object #<Object> has no method '_markModified'
at EmbeddedDocument.markModified (mongoose-version.git/node_modules/mongoose/lib/types/embedded.js:63:24)
at EmbeddedDocument.Document._set (mongoose-version.git/node_modules/mongoose/lib/document.js:551:10)
at EmbeddedDocument.Document.set (mongoose-version.git/node_modules/mongoose/lib/document.js:476:10)
at EmbeddedDocument.Object.defineProperty.set [as _id] (mongoose-version.git/node_modules/mongoose/lib/document.js:1123:45)
at _clone (mongoose-version.git/node_modules/clone/clone.js:65:22)
at _clone (mongoose-version.git/node_modules/clone/clone.js:65:24)
at _clone (mongoose-version.git/node_modules/clone/clone.js:65:24)
at _clone (mongoose-version.git/node_modules/clone/clone.js:65:24)
at clone (mongoose-version.git/node_modules/clone/clone.js:76:18)
at module.exports (mongoose-version.git/lib/clone-schema.js:4:24)
at Object.module.exports [as array] (mongoose-version.git/lib/strategies/array.js:8:24)
at module.exports (mongoose-version.git/lib/version.js:21:33)
at Schema.plugin (mongoose-version.git/node_modules/mongoose/lib/schema.js:533:3)
at Context.<anonymous> (mongoose-version.git/test/version.js:139:20)
at Test.Runnable.run (node_modules/mocha/lib/runnable.js:196:15)
at Runner.runTest (node_modules/mocha/lib/runner.js:343:10)
at Runner.runTests.next (node_modules/mocha/lib/runner.js:389:12)
at next (node_modules/mocha/lib/runner.js:269:14)
at Runner.hooks (node_modules/mocha/lib/runner.js:278:7)
at next (node_modules/mocha/lib/runner.js:226:23)
at Runner.hook (node_modules/mocha/lib/runner.js:246:5)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
If I try something like this:
I get:
Any idea?