Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8148775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:42:44+00:00 2026-06-06T14:42:44+00:00

I am using the Mongo Ruby driver and have this block of Ruby code

  • 0

I am using the Mongo Ruby driver and have this block of Ruby code before and after line 171 in my code, which is apparently the source of the error below it (the query.each line is line 171):

    query = get_callback.call( "databases", id )
    if query.count > 0
      puts query.count.inspect + " results: " + query.inspect
      res = {}
      query.each do |result|
        puts result.inspect
      end
    else
      puts "No results" + res.inspect
      res = {}
    end

The error:

1 results: <Mongo::Cursor:0x3fc15642c154 namespace='myproj.databases' @selector={"_id"=>BSON::ObjectId('4fe120e4a2f9a386ed000001')} @cursor_id=>
TypeError - can't convert Mongo::Cursor into Integer:
        /Users/myuser/.rvm/gems/ruby-1.9.3-p194/gems/bson-1.6.4/lib/bson/byte_buffer.rb:156:in `pack'
        /Users/myuser/.rvm/gems/ruby-1.9.3-p194/gems/bson-1.6.4/lib/bson/byte_buffer.rb:156:in `put_int'
        /Users/myuser/.rvm/gems/ruby-1.9.3-p194/gems/mongo-1.6.4/lib/mongo/cursor.rb:603:in `construct_query_message'
        /Users/myuser/.rvm/gems/ruby-1.9.3-p194/gems/mongo-1.6.4/lib/mongo/cursor.rb:466:in `send_initial_query'
        /Users/myuser/.rvm/gems/ruby-1.9.3-p194/gems/mongo-1.6.4/lib/mongo/cursor.rb:459:in `refresh'
        /Users/myuser/.rvm/gems/ruby-1.9.3-p194/gems/mongo-1.6.4/lib/mongo/cursor.rb:128:in `next'
        /Users/myuser/.rvm/gems/ruby-1.9.3-p194/gems/mongo-1.6.4/lib/mongo/cursor.rb:291:in `each'
        /Users/myuser/Code/myproj/my_file.rb:171:in `block in initialize'

My query object: {"_id"=>BSON::ObjectId('4fe120e4a2f9a386ed000001')}

I have not the faintest idea what’s causing this. I’ve verified the object I’m finding exists and the query.count shows that there’s a result in my Mongo::Cursor.

I’ve not found any examples of the issue on Google and every Mongo/Ruby on the web I’ve found uses an each iterator just like I do. Anyone know what’s the cause of this error? I notice I also get it when trying to use to_a to cast the collection to a JSON-usable object.


For what it’s worth, here’s the relevant part of byte_buffer.rb is below. The line with << is line 156.

def put_int(i, offset=nil)
  @cursor = offset if offset
  if more?
    @str[@cursor, 4] = [i].pack(@int_pack_order)
  else
    ensure_length(@cursor)
    @str << [i].pack(@int_pack_order)
  end
  @cursor += 4
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:42:45+00:00Added an answer on June 6, 2026 at 2:42 pm

    This happens when you pass nil to a Ruby Mongo driver limit() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started using NoSQL with Ruby. Here's the code I have require 'mongo' require
I am using mongo-ruby-driver, I want to get stats/query graphs to show for Mongo.
I have a Rails 3.1 app, running on Ruby 1.9.2, Mongo 2.0.2, using Mongoid
I want to upsert a document with the mongo-ruby-driver using something like the following-
Uing Ruby (1.8.7) and Mongo Driver, I've written this: @data['Users'] = [] @database['user_facilities'].find({ :facility_id
I'm retrieving results from mongo based on a geo query using the ruby driver.
I'm using the Mongo LINQ Driver for C#, works great. Sorting a lot of
I have a mongoose and connect-mongo module instance in ym app. I am using
Ok i am using mongo db and have a repeating region on my page:
In ruby using the mongo gem I can't find any documentation on how to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.