def count(skip_and_limit = false)
command = BSON::OrderedHash["count", @collection.name, "query", @selector]
if skip_and_limit
command.merge!(BSON::OrderedHash["limit", @limit]) if @limit != 0
command.merge!(BSON::OrderedHash["skip", @skip]) if @skip != 0
end
command.merge!(BSON::OrderedHash["fields", @fields])
response = @db.command(command, :read => @read, :comment => @comment)
return response['n'].to_i if Mongo::Support.ok?(response)
return 0 if response['errmsg'] == "ns missing"
raise OperationFailure.new("Count failed: #{response['errmsg']}", response['code'], response)
end