2

I just added Meteor collection2 to my app. And in a file in the server folder I added the code:

Schema = {}


Schema.User = new SimpleSchema(
  _id:
    type: String
    regEx: SimpleSchema.RegEx.Id

  username:
    type: String
    regEx: /^[a-z0-9A-Z_]{3,15}$/

  emails:
    type: [Object]
    optional: true

  "emails.$.address":
    type: String
    regEx: SimpleSchema.RegEx.Email

  "emails.$.verified":
    type: Boolean

  createdAt:
    type: Date

)

Meteor.users.attachSchema Schema.User

and it is crashing my app with the error:

W20140907-02:06:32.777(-4)? (STDERR) /Users/Nearpoint/.meteor/packages/meteor-tool/.1.0.25.2ltu8i++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/lib/node_modules/fibers/future.js:173
W20140907-02:06:32.777(-4)? (STDERR)                        throw(ex);
W20140907-02:06:32.777(-4)? (STDERR)                              ^
W20140907-02:06:32.792(-4)? (STDERR) Error: undefined is not allowed by the schema
W20140907-02:06:32.792(-4)? (STDERR)     at getErrorObject (packages/aldeed:collection2/collection2.js:489)
W20140907-02:06:32.792(-4)? (STDERR)     at doValidate (packages/aldeed:collection2/collection2.js:472)
W20140907-02:06:32.792(-4)? (STDERR)     at Meteor.Collection.(anonymous function) [as update] (packages/aldeed:collection2/collection2.js:282)
W20140907-02:06:32.792(-4)? (STDERR)     at UserConnections.upsert.$set.ipAddr (packages/mizzao:user-status/status.coffee:94:15)

I am running Meteor 0.9.0. And I am attaching the schema code on the server. I do not know what I am doing wrong. I even tried removing all schema fields except _id and it still did not work.

4

3 回答 3

7

NB - to resolve this if you're using mizzao:user-status, you just need to allow that package to add a status field to your user doc:

Schema.User = new SimpleSchema(
  ...
  status: {
    type: Object,
    optional: true,
    blackbox: true
  }
});
于 2014-12-30T17:01:27.553 回答
1

I had the exact same problem. By any chance, are you using the mizzao:user-status package? It inserts an additional field for keeping track of user connections. https://github.com/mizzao/meteor-user-status

Any additional package that adds fields to Meteor.users docs before you even set up accounts may cause this problem. Specifically, when you sign on, it will create a blank user object with only the connection fields, which is clearly not allowed by your schema.

于 2014-12-07T11:18:31.630 回答
0

Since Users is a default Meteor collection there's probably a property it wants to save that you're not allowing.

I would look at the database using RoboMongo or another tool and make sure you include all the properties.

于 2014-09-11T16:09:03.530 回答