May 2018
Intermediate to advanced
470 pages
13h 54m
English
The answerObjects and wrongObjects arrays in a game document must contain at least one VRObject document in each array when being saved in the game collection. To add validation for a minimum array length to the game schema, we will add the following custom validation checks to the answerObjects and wrongObjects paths in GameSchema.
mern-vrgame/server/models/game.model.js:
GameSchema.path('answerObjects').validate(function(v) { if (v.length == 0) { this.invalidate('answerObjects', 'Must add alteast one VR object to collect') }}, null)
GameSchema.path('wrongObjects').validate(function(v) { if (v.length == 0) { this.invalidate('wrongObjects', 'Must add alteast one other VR object') }}, null)
Read now
Unlock full access