mongodb/mongoid · error

Multiple $text expressions per query are not currently suppo

Error message

Multiple $text expressions per query are not currently supported by the server

What it means

Error "Multiple $text expressions per query are not currently supported by the server" thrown in mongodb/mongoid.

Source

Thrown at lib/mongoid/criteria/queryable/selectable.rb:743

        # @param [ String | Symbol ] terms A string of terms that MongoDB parses
        #   and uses to query the text index.
        # @param [ Hash ] opts Text search options. See MongoDB documentation
        #   for options.
        #
        # @return [ Selectable ] The cloned selectable.
        def text_search(terms, opts = nil)
          raise Errors::CriteriaArgumentRequired, :terms if terms.nil?

          clone.tap do |query|
            criterion = { '$text' => { '$search' => terms } }
            criterion['$text'].merge!(opts) if opts
            if query.selector['$text']
              # Per https://www.mongodb.com/docs/manual/reference/operator/query/text/
              # multiple $text expressions are not currently supported by
              # MongoDB server, but build the query correctly instead of
              # overwriting previous text search condition with the currently
              # given one.
              Mongoid.logger.warn('Multiple $text expressions per query are not currently supported by the server')
              query.selector = { '$and' => [ query.selector ] }.merge(criterion)
            else
              query.selector = query.selector.merge(criterion)
            end
          end
        end

        # This is the general entry point for most MongoDB queries. This either
        # creates a standard field: value selection, and expanded selection with
        # the use of hash methods, or a $where selection if a string is provided.
        #
        # @example Add a standard selection.
        #   selectable.where(name: "syd")
        #
        # @example Add a javascript selection.
        #   selectable.where("this.name == 'syd'")
        #
        # @param [ [ Hash | String ]... ] *criterion The standard selection

View on GitHub (pinned to 0da0e23d71)

When it happens

Trigger: Thrown at lib/mongoid/criteria/queryable/selectable.rb:743 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of mongodb/mongoid@0da0e23d71 (2026-08-23). Data as JSON: /api/errors/1fc2ac0f35bc3cfd. Report an issue: GitHub.