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 8380747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:32:09+00:00 2026-06-09T16:32:09+00:00

I have an array of Mongo objects returned by a geolocation query such as

  • 0

I have an array of Mongo objects returned by a geolocation query such as :

@data = Record.geo_near([lng,lat], :max_distance => dist, :unit => :m, :spherical => true)

I’m then trying to serialize the response based on the expected format :

respond_to do |format|
    format.html 
    format.json { render json: @data, :status => 200 } # Not working
    format.xml { render xml: @data, :status => 200 } # Working !
end

The weird thing is that everything go smoothly with XML, but I get this error with JSON :

ActiveSupport::JSON::Encoding::CircularReferenceError in BouncesController#populars
object references itself

I found this post relating to the same kind of error, but the validated answer did not work for me.

Any ideas?

EDIT

Here is my model for which the issue is happening :

class MyModel
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Spacial::Document

  spacial_index :loc, :min => -180, :max => 180
  belongs_to :user

  field :text, :type => String
  field :loc, :type => Array, spacial: true
  field :accuracy, :type => Float

  def as_json(options={})
  {
  "id" => self.id,
  "text" => self.text,
  "loc" => self.loc,
  "accuracy" => self.accuracy,
  "user" => {
    "id" => self.user['_id'],
    "login" => self.user['login'],
    "role" => self.user['role']
  },
  "created_at" => self.created_at,
  "updated_at" => self.updated_at
  }
  end
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-09T16:32:10+00:00Added an answer on June 9, 2026 at 4:32 pm

    For now I have resolved the issue by downgrading my gems as follow :

    gem 'mongo', '1.4.0'
    gem "mongoid", "~> 2.4"
    gem "bson_ext", "~> 1.5"
    

    There is still the possibility to use the following hack, but it prevents you to format yourself the json output in your model.

    format.json { render json: Hash.from_xml(@data.to_xml).to_json, :status => 200 }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a trip model that contains an array of lat/lng pairs class Trip
I have array of strings, String[] data and it's 10 elements has value P
When I have array of objects, when I type the name of variable in
I have created an array in my mongo document, so it looks a bit
I have a Mongo document which holds an array of elements. I'd like to
I have an array of objects taken from mongodb. Every element in the array
Let's say I have the following data model in Mongo: { _id: ..., name:
I have the following MongoDB object stored in my Mongo database: array ( '_id'
I have mongo collection array as below [_id] => MongoId Object ( [$id] =>
I have array INPUTFILES with n files INPUTFILES=( file_0 ... files_n-1 ) And i

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.