SimpleSchema déclaration d'un tableau

Bonjour,
Je voudrais déclarer un tableau de chaines dans un champ d’un document avec SimpleSchema.

Clients.attachSchema(new SimpleSchema({

“cli_comment”: {type:String,optional:true},
“cli_keyCliFac”: [{“keyCliFac”:String,optional:true}]. // optional:true pour pouvoir avoir un tableau vide
}));

et pour inserer

Clients.insert({

“cli_comment”: ‘’,
“cli_keyCliFac”: [{“keyCliFac”:“PREM”},{“keyCliFac”:“SUIV”}]
});

Aucune erreur n’est détectée !!!
Mais le “cli_keyCliFac” reste désespérément vide ( tableau de 0 élément)

Je pense qu’il y a une erreur dans la déclaration de SimpleSchema,

Est-ce que quelqu’un a une idée de la marche à suivre pour faire cette déclaration.
Merci
YC

You can’t nest keys like this:

"cli_keyCliFac": [{"keyCliFac":String,optional:true}]

Instead, you have to declare

"cli_keyCliFac": {
    type: [Object]
}

and define separate keys for its sub-keys:

"cli_keyCliFac.keyCliFac": {
    type: String,
    optional: true
}

Thanks for your reply but it returns me the following error :

"cli_keyCliFac":  {type:[Object]},
"cli_keyCliFac.keyCliFac":{type:String,optional:true}

Error: Invalid definition for cli_keyCliFac field: “type” may not be an array. Change it to Array.

when you do:
"cli_keyCliFac": {type:[Object]}, "cli_keyCliFac.keyCliFac":{type:String,optional:true}
you are declaring a array of objects, do this instead:
"cli_keyCliFac": {type:Object}, "cli_keyCliFac.keyCliFac":{type:String,optional:true}

Yes, in fact I would like to declare an array of objects.
This simple statement

Clients.attachSchema(new SimpleSchema({
“cli_keyCliFac”: {
type:[Object]
}
}));

genere the error :
Error: Invalid definition for cli_keyCliFac field: “type” may not be an array. Change it to Array.

Can we not declare an array of objects?

Hey @yvancoyaud I would hazard a guess that you are using the npm version of simpl-schema? The syntax changed a bit to the atmosphere version. If indeed you are, then according to the docs you may use [Object] only in shorthand declarations. Otherwise, you will have to declare it like so (from the docs):

const schema = new SimpleSchema({
  addresses: {
    type: Array,
    minCount: 1,
    maxCount: 4
  },
  'addresses.$': Object,
  'addresses.$.street': String,
  'addresses.$.city': String,
});

You need to set the type to Array, which is exactly what the error tells you to do.
Let me know if that solved the issue.

Here is the correct syntax.

Thank you very much tomsp

Merci
YC