SimpleSchema Collection2 no longer sees unique option

Hi everyone,

I am migrating a meteor app from 1.4 to 1.9… so far, not too bad… but I’m now getting an error that seems to indicate that SimpleSchema doesn’t see the meteor-schema-index extended options, index and unique, even though the docs say meteor-schema-index is included in meteor-collection2 (and the code worked fine in the 1.4 version).

If I remove the unique=true option from the definition for the phone field below it will not generate the error:

Users.js:

Users = Meteor.users;

UserProfileSchema = new SimpleSchema({
...
    phone: { type: String, label: "Phone Number", min: 9, max: 15, unique: true }
...
}

Error:

 Error: Invalid definition for phone field.
W20200205-10:48:43.388(-5)? (STDERR)     at packages/aldeed_simple-schema.js:1429:13

Note:
I have simpl-schema in package.json. In .meter/packages I have aldeed:collection2, aldeed:autoform and aldeed:simple-schema.

Any ideas what’s up?

Try adding the package directly:

meteor add aldeed:schema-index

Thanks that was the first thing I tried. Unfortunately, didn’t work. For now I have rolled back to old versions of SimpleSchema and meteor-collection-2, which do work:

aldeed:simple-schema@1.5.4  
aldeed:autoform@5.8.1
aldeed:collection2@2.10.0

As both autoform and collection2 are on new versions now (6 and 3), I’m not surprised, but I am surprised I can’t find anything in the migration docs that indicates I’d get this kind of error.

I looked through the code in both collection2 and aldeed:schema-index repos - it should work. Nothing obvious is breaking this…

You are sure you added, aldeed:schema-index? I don’t see that in your list above.

Also, remove aldeed:simple-schema you don’t need it. Instead you should install the npm module: meteor npm i simpl-schema.

Yes, as noted in my reply, I tried adding aldeed:schema-index already directly to meteor/packages. It did not work.

As noted in my question, per the requirement, I added simpl-schema to the app root package.json when attempting the upgrade.

Neither worked, so I rolled it back to what did work, which is what I listed.

Did you do extend options?

import SimpleSchema from 'simpl-schema'
SimpleSchema.extendOptions(['index', 'unique'])

I’ll try that… since this code was working previously, unaltered, and now works fine with the older versions of the packages, I’m going to shelve this for now. I need to tackle the other big issue upgrading brings… Flowrouter routes (I’m getting: Error : There is no route for the path: / …as if the class is not initializing…)

Ok, if you ask a question, get an answer and you shelve the matter, next time someone comes here will have to ask “So, you asked a question and got an answer. Did it work?” This is a community and we all have to benefit in one way or another so I’d appreciate it if you finalized your queries in a different way than “shalved”. This was a request for help. If you look at other requests for help, they tend to end up in a [SOLVED] status. What is the status of your request?!

I appreciate the suggestions, thanks @paulishca. Tried importing and direclty extending. Unfortunately I get the same error. I will keep looking into this…

Hi there, I had the same issue as @marcusmarcus and could not fix it with all of your suggestions. Went through more or less the same mitigations. If there is anyone with a good tip I would be very thankful too :smile:

I have

aldeed:collection2@3.0.6
and NPM - "simpl-schema": "^1.5.6",

Absolutely no problems.

import SimpleSchema from 'simpl-schema'
SimpleSchema.extendOptions(['index', 'unique'])

Schemas.Tags = new SimpleSchema({
  tag: { type: String, index: 1, unique: true }
})

It could be that the initial issue here above is the presence of the aldeed:simple-schema package which was deprecated in favor of the NPM version.

1 Like

Interestingly enough, a year later, migrating now to 2.4, mostly without difficulty, but again SimpleSchema complaining:

Error: Invalid definition for venueId field: "type" option is required ... at ...
/node_modules/simpl-schema/dist/SimpleSchema.js:1188:22

We defined our model schemas with decorators to make it easier to modify with common features like soft delete and timestamps:

@model('venues')
@schema ({
    venueId: { type: String },
    name: { type: String }
}, ['archivable'] )

This was working prior to the update to 2.4.