Meteor-Community-Packages / meteor-collection2

A Meteor package that extends Mongo.Collection to provide support for specifying a schema and then validating against that schema when inserting and updating.
https://packosphere.com/aldeed/collection2
MIT License
1.02k stars 108 forks source link

attachSchema broken since meteor 1.4.2 update #353

Closed neurosoup closed 8 years ago

neurosoup commented 8 years ago

Since the 1.4.2 meteor update the attachSchema function leads to this error :

allow-deny.js:477Uncaught TypeError: Cannot read property 'insert' of undefined

image

Here is the code calling the attachSchema function : const Clusters = new ClustersCollection('clusters') Clusters.attachSchema(Schemas.Clusters)

The cluster collection extends a CollectionBase class wich is defined as follow

` export default class CollectionBase extends Mongo.Collection {

constructor(collectionName) { super(collectionName)
}

beforeInsert(doc) { }

afterInsert(doc) { }

beforeUpdate(selector, modifier, options) { }

afterUpdate(selector, modifier, options) { }

update(selector, modifier, options, callback) {
try { this.beforeUpdate(selector, modifier, options)
const res = super.update(selector, modifier, options, callback) if (res.insertedId) { const doc = super.findOne(res.insertedId) this.afterInsert(doc) } else { this.afterUpdate(selector, modifier, options) } return res } catch (e) { Logger.error(e) throw e } }

insert(doc, callback) { try { this._c2._simpleSchema.clean(doc) this.beforeInsert(doc) const res = super.insert(doc, callback) doc._id = res this.afterInsert(doc) return doc._id } catch (e) { Logger.error(e) throw e } }

}`

I'm trying to investigate further.

Thanks

neurosoup commented 8 years ago

Sorry,

seems to be a Mongo.Collection inheritance problem. Something has changed since the meteor 1.4.2 and I can't extend from Mongo.Collection as before.

I Close the issue.

domq commented 7 years ago

For the benefit of the next person to wind up here by searching the error message: in my case, the issue was that my SimpleSchema was the one out of aldeed:simple-schema, as opposed to the one out of simpl-schema as it should.

Here is what I did to fix my own symptom: