mongoose-version icon indicating copy to clipboard operation
mongoose-version copied to clipboard

Plugin is broken

Open tirithen opened this issue 10 years ago • 11 comments

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]

tirithen avatar May 09 '14 07:05 tirithen

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.

niftylettuce avatar Jun 02 '14 22:06 niftylettuce

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?

saintedlama avatar Jun 03 '14 06:06 saintedlama

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]

sandytrinh avatar Aug 28 '14 02:08 sandytrinh

+1 - same here

desmondmorris avatar Sep 30 '14 21:09 desmondmorris

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

ehmicky avatar Mar 26 '15 11:03 ehmicky

+1 i also get the same errors.

kirrg001 avatar Jun 14 '15 21:06 kirrg001

+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]

michaelgmcd avatar Jun 22 '15 15:06 michaelgmcd

+1 Same error for me. I'm using [email protected] and [email protected]

sergiofm avatar Apr 13 '16 03:04 sergiofm

Anyone still maintaining this project. I dont see any activity ?

ghost avatar Apr 15 '16 06:04 ghost

@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 :)

yitomok avatar Jun 07 '16 02:06 yitomok

#22 This should fix the problem, thanks a lot @saintedlama!

yitomok avatar Jun 17 '16 06:06 yitomok