Schema.prototype.eachPath()

Parameters
  • fn «Function» callback function
Returns:
  • «Schema» this

Iterates the schemas paths similar to Array#forEach.

The callback is passed the pathname and the schemaType instance.

Example:

  1. const userSchema = new Schema({ name: String, registeredAt: Date });
  2. userSchema.eachPath((pathname, schematype) => {
  3. // Prints twice:
  4. // name SchemaString { ... }
  5. // registeredAt SchemaDate { ... }
  6. console.log(pathname, schematype);
  7. });