node.js - Multi-dimensional array in Mongoose schema -


how can define multi-dimensional array in mongoose schema? want have 2d array in mongoose schema in order locate room in hotel this.

var room = new schema({    number: number,    type: string, // room type id     });  var hotel = new schema({    ...    rooms: [[room]]     }); 

here's error get...

d:\projects\hotelbox\node_modules\mongoose\lib\schema\array.js:58 this.caster = new caster(null, castoptions);               ^ typeerror: object not function @ new schemaarray 

i can fix defining rooms schema.types.mixed can't validate room data @ time of creation.

afaik, there no such support in mongoose multidimensional arrays utilisation.

that being said, , have been pointed, can workaround using schema.types.mixed schematype, lose goodies came use native mongoose types.

however, can overcome definining own validations using custom validators, pointed @ official docs (they easy use). caveat custom validations triggered when saving instance.

if need trigger validations , initilization time, can use more low-level middleware hooks gives fine grained control since can invoke them @ following actions:

  • init
  • validate
  • save
  • remove

(note init hook)

hope helps overcome use case.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -