Method: Mongo::SearchIndex::View#each

Defined in:
lib/mongo/search_index/view.rb

#each(&block) ⇒ self | Enumerator

Iterate over the search indexes.

Parameters:

  • block (Proc)

    if given, each search index will be yieleded to the block.

Returns:

  • (self | Enumerator)

    if a block is given, self is returned. Otherwise, an enumerator will be returned.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/mongo/search_index/view.rb', line 111

def each(&block)
  @result ||= begin
    spec = {}.tap do |s|
      s[:id] = requested_index_id if requested_index_id
      s[:name] = requested_index_name if requested_index_name
    end

    collection.with(read_concern: {}).aggregate(
      [ { '$listSearchIndexes' => spec } ],
      aggregate_options
    )
  end

  return @result.to_enum unless block

  @result.each(&block)
  self
end