Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin is broken #10

Open
tirithen opened this issue May 9, 2014 · 11 comments
Open

Plugin is broken #10

tirithen opened this issue May 9, 2014 · 11 comments

Comments

@tirithen
Copy link

tirithen commented May 9, 2014

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]

@niftylettuce
Copy link

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.

saintedlama added a commit that referenced this issue Jun 3, 2014
@saintedlama
Copy link
Owner

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?

@sandytrinh
Copy link

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]

@desmondmorris
Copy link

+1 - same here

@ehmicky
Copy link

ehmicky commented Mar 26, 2015

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

@kirrg001
Copy link

+1 i also get the same errors.

@michaelgmcd
Copy link

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

@sergiofm
Copy link

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

@ghost
Copy link

ghost commented Apr 15, 2016

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

@yitomok
Copy link
Contributor

yitomok commented Jun 7, 2016

@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
Copy link
Contributor

yitomok commented Jun 17, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants