Schema.prototype.pick()

Parameters
  • paths «Array» list of paths to pick

  • [options] «Object» options to pass to the schema constructor. Defaults to this.options if not set.

Returns:
  • «Schema»

Returns a new schema that has the picked paths from this schema.

This method is analagous to Lodash’s pick() function for Mongoose schemas.

Example:

  1. const schema = Schema({ name: String, age: Number });
  2. // Creates a new schema with the same `name` path as `schema`,
  3. // but no `age` path.
  4. const newSchema = schema.pick(['name']);
  5. newSchema.path('name'); // SchemaString { ... }
  6. newSchema.path('age'); // undefined