lib/mongo/collection/view/readable.rb in mongo-2.15.0.alpha vs lib/mongo/collection/view/readable.rb in mongo-2.15.0

- old
+ new

@@ -1,5 +1,8 @@ +# frozen_string_literal: true +# encoding: utf-8 + # Copyright (C) 2014-2020 MongoDB Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -228,10 +231,16 @@ def estimated_document_count(opts = {}) unless view.filter.empty? raise ArgumentError, "Cannot call estimated_document_count when querying with a filter" end + %i[limit skip].each do |opt| + if @options.key?(opt) + raise ArgumentError, "Cannot call estimated_document_count when querying with #{opt}" + end + end + Mongo::Lint.validate_underscore_read_preference(opts[:read]) read_pref = opts[:read] || read_preference selector = ServerSelector.get(read_pref || server_selector) with_session(opts) do |session| context = Operation::Context.new(client: client, session: session) @@ -625,13 +634,13 @@ def collation(doc = nil) configure(:collation, doc) end def server_selector - if options[:session] && options[:session].in_transaction? + @server_selector ||= if options[:session] && options[:session].in_transaction? ServerSelector.get(read_preference || client.server_selector) else - @server_selector ||= ServerSelector.get(read_preference || collection.server_selector) + ServerSelector.get(read_preference || collection.server_selector) end end def parallel_scan(cursor_count, options = {}) if options[:session]