mongoose-version
mongoose-version copied to clipboard
Plugin is broken
The application crashes when plugin is used.
Code in my Page.js
var version = require('mongoose-version');
module.exports = function (mongoose) {
var model, schema;
schema = new mongoose.Schema({
title: { type: String, required: true, trim: true },
content: { type: String, trim: true }
});
schema.plugin(version, { strategy: 'collection', collection: 'PageVersions' });
model = mongoose.model('Page', schema);
return model;
};
The error I get is:
/projectpath/node_modules/mongoose-version/node_modules/mongoose/lib/schema.js:362
throw new TypeError('Undefined type at `' + path +
^
TypeError: Undefined type at `paths.title`
Did you try nesting Schemas? You can only nest using refs or arrays.
at Function.Schema.interpretAsType (/projectpath/node_modules/mongoose-version/node_modules/mongoose/lib/schema.js:362:11)
at Schema.path (/projectpath/node_modules/mongoose-version/node_modules/mongoose/lib/schema.js:305:29)
at Schema.add (/projectpath/node_modules/mongoose-version/node_modules/mongoose/lib/schema.js:217:12)
at Schema.add (/projectpath/node_modules/mongoose-version/node_modules/mongoose/lib/schema.js:212:14)
at new Schema (/projectpath/node_modules/mongoose-version/node_modules/mongoose/lib/schema.js:73:10)
at Mongoose.model (/projectpath/node_modules/mongoose-version/node_modules/mongoose/lib/index.js:293:14)
at Object.module.exports [as collection] (/projectpath/node_modules/mongoose-version/lib/strategies/collection.js:26:46)
at module.exports (/projectpath/node_modules/mongoose-version/lib/version.js:24:33)
at Schema.plugin (/projectpath/node_modules/mongoose/lib/schema.js:570:3)
at module.exports (/projectpath/models/Page.js:12:10)
If using strategy 'array' instead I get the error:
/projectpath/node_modules/mongoose-version/node_modules/mongoose/lib/schema/array.js:58
this.caster = new caster(null, castOptions);
^
TypeError: object is not a function
at new SchemaArray (/projectpath/node_modules/mongoose-version/node_modules/mongoose/lib/schema/array.js:58:19)
at Function.Schema.interpretAsType (/projectpath/node_modules/mongoose-version/node_modules/mongoose/lib/schema.js:350:12)
at Schema.path (/projectpath/node_modules/mongoose-version/node_modules/mongoose/lib/schema.js:305:29)
at Schema.add (/projectpath/node_modules/mongoose-version/node_modules/mongoose/lib/schema.js:217:12)
at new Schema (/projectpath/node_modules/mongoose-version/node_modules/mongoose/lib/schema.js:73:10)
at Object.module.exports [as array] (/projectpath/node_modules/mongoose-version/lib/strategies/array.js:11:27)
at module.exports (/projectpath/node_modules/mongoose-version/lib/version.js:24:33)
at Schema.plugin (/projectpath/node_modules/mongoose/lib/schema.js:570:3)
at module.exports (/projectpath/models/Page.js:12:10)
at /projectpath/models/index.js:15:60
I am using [email protected] and [email protected]
I get the same error with caster. As soon as I use the plugin on an existing project it bugs out (and I'm using same version of owl-deepcopy and mongoose as the tests). I've tried wiping DB as well.
We're using a new clone functionality now and we've tests that try to verify that this issue does not exist anymore. Could you give the most current version from master branch a try?
Hi there! I've pulled down the master branch and got the same error as @tirithen when using the collection strategy. I'm using [email protected] and [email protected]
+1 - same here
I have the same problem after upgrading Mongoose to 3.8.25. It also seems to come from the deep copy of the clonedSchema
object. The returned value somehow does not fit the new Mongoose versions anymore.
I run mongoose-version 0.2.4
+1 i also get the same errors.
+1 for errors on an existing project. It appears that mongoose-version uses [email protected]
. My project is using [email protected]
. Could this be the issue? I'm using [email protected]
+1 Same error for me. I'm using [email protected] and [email protected]
Anyone still maintaining this project. I dont see any activity ?
@monk8800 What version of Mongoose you using? The mongoose-version published on npm doesn't have the latest updates, it won't work with Mongoose 4+, you need the latest source from git.
I did send a pull request but I guess @saintedlama is busying on other stuff :)
#22 This should fix the problem, thanks a lot @saintedlama!