id(id) {
    let casted;
    let sid;
    let _id;

    try {
      casted = castObjectId(id).toString();
    } catch (e) {
      casted = null;
    }

    for (const val of this) {
      if (!val) {
        continue;
      }

      _id = val.get('_id');

      if (_id === null || typeof _id === 'undefined') {
        continue;
      } else if (_id instanceof Document) {
        sid || (sid = String(id));
        if (sid == _id._id) {
          return val;
        }
      } else if (!isBsonType(id, 'ObjectId') && !isBsonType(_id, 'ObjectId')) {
        if (id == _id || utils.deepEqual(id, _id)) {
          return val;
        }
      } else if (casted == _id) {
        return val;
      }
    }

    return null;
  }
Searches array items for the first document with a matching _id.

#### Example:

    const embeddedDoc = m.array.id(some_id);

@return {EmbeddedDocument|null} the subdocument or null if not found.
@param {ObjectId|String|Number|Buffer} id
@TODO cast to the _id based on schema for proper comparison
@method id
@api public
@memberOf MongooseDocumentArray