mongodbmeteorsimple-schemameteor-collection2

Meteor SimpleSchema and _id field


A little bit question, did you include the _id field into your SimpleSchema ?

If the answer is no ! and if you use Collection2, did you check the _id argument into your methods ?

Example :

equipments.update': (equipmentId, equipment) => {
    check({ _id: equipmentId }, Equipments.schema.pick('_id'));
    check(equipment, Equipments.schema.omit('_id'));
    // ...
},

Thanks :-) Aurélien


Solution

    1. There is no reason to include the _id field unless you want to force your mongo document IDs to follow a specific format in which case, you may explicitly specify the _id field in simple shcema and have a custom function / autoValue generate the value of the field.

    2. From what I know, collection2 usually drops the _id field before it runs autoValue. Reference: here