SimpleSchema: "Match error: Unknown key in field XXX"

Hi,

I’m trying to use SimpleSchema with an object and getting this error:
“Match error: Unknown key in field XXX”. I can’t figure out what the problem is because the object seems perfectly good. What does this error message means? What’s the key of a field?

It means your schema is invalid. And until you show it, we can’t really help you.

Hi,

Thanks for the quick reply!

Here’s the schema:

schema.guest = new SimpleSchema({
  createdAt: {type: Date},
  updatedAt: {type: Date},
  accepted: {type: Boolean},
  avatar: {type: String},
  confirmationCode: {type: String, optional: true},
  email: {type: String, optional: true},
  _id: {type: String},
  location: {type: String, optional: true},
  name: {type: String},
  phone: {type: String, optional: true},
  threadId: {type: String},
  lastEarn: {type: String, optional: true},
  lastMsgDate: {type: String},
  lastStatus: {type: String},
  lastSubject: {type: String},
  msgs: {type: [schema.message]}
});

Can you also paste your form? Or the method in which you add the object? I’ll check it at my computer.

The key of a field is basically what createdAt or updatedAt is. Your check method can’t find this key in the schema.

Also, @zimme wrote very nice packages that take care of stuff like createdAt or updatedAt. Check out https://atmospherejs.com/zimme/collection-timestampable

Meteor.call("Guests.upsert", guest, (err, res) => {
  if (err)
    Logger.error(err, ["method", "Casper.parseInbox", "Guests.upsert"]);
  console.log(res);
});

If I console.log guest before the call, it seems perfectly good. First it had a problem with _id. I tried to omit it from the check (and added optional: true to the schema), but then it had the same problem with avatar.
I also tried to skip the check - the inserted document seemed okay.

The _id field will be added to your object by default, no need to add it to the schema.

schema.message and the object are still missing.

I’m going out to watch Star Wars, so good luck. :slight_smile:

I’m using my own _id and it comes with the object.
Here’s the rest of the schema:

schema.inquiry = new SimpleSchema({
  apartment: {type: String},
  date: {type: String},
  earn: {type: String},
  guests: {type: Number}
});

schema.preApprove = new SimpleSchema({
  apartment: {type: String},
  date: {type: String},
  earn: {type: String},
  guests: {type: Number},
  removeUrl: {type: String},
  specialOffer: {type: Boolean}
});


schema.message = new SimpleSchema({
  inquiry: {type: schema.inquiry, optional: true},
  isResponse: {type: Boolean},
  msg: {type: String},
  notAvailable: {type: Boolean},
  preApprove: {type: schema.preApprove, optional: true},
  time: {type: Date}
});

May the force be with you :smile:

I’m trying to figure out this message, but still don’t get it:
Match error: Unknown key in field _id

The key is _id and it has a valid value, it’s not a field. What does it mean? :confounded:

Hm, I was wrong, the quotes are there because I was using console.log(JSON.stringify(obj)).
So it’s not the cause, and I don’t have a clue… again.

Ok, I was a complete idiot and was checking against the wrong schema…

1 Like

how did you solve this problem? i’m having a same issue.

Yeah same… I’m assuming something is wrong with the schema (as per other user’s using of the wrong schema)