_cast(value) {
    let populated = false;
    let Model;

    const parent = this[arrayParentSymbol];
    if (parent) {
      populated = parent.$populated(this[arrayPathSymbol], true);
    }

    if (populated && value !== null && value !== undefined) {
      // cast to the populated Models schema
      Model = populated.options[populateModelSymbol];
      if (Model == null) {
        throw new MongooseError('No populated model found for path `' + this[arrayPathSymbol] + '`. This is likely a bug in Mongoose, please report an issue on github.com/Automattic/mongoose.');
      }

      // only objects are permitted so we can safely assume that
      // non-objects are to be interpreted as _id
      if (Buffer.isBuffer(value) ||
          isBsonType(value, 'ObjectId') || !utils.isObject(value)) {
        value = { _id: value };
      }

      // gh-2399
      // we should cast model only when it's not a discriminator
      const isDisc = value.schema && value.schema.discriminatorMapping &&
          value.schema.discriminatorMapping.key !== undefined;
      if (!isDisc) {
        value = new Model(value);
      }
      return this[arraySchemaSymbol].caster.applySetters(value, parent, true);
    }

    return this[arraySchemaSymbol].caster.applySetters(value, parent, false);
  }
Casts a member based on this arrays schema.

@param {any} value
@return value the casted value
@method _cast
@api private
@memberOf MongooseArray