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

  • SEARCH
  • Home
  • 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 6388937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:20:31+00:00 2026-05-25T03:20:31+00:00

In our Rails app environment (ruby 1.8.7 / rails 2.3.12) I can run the

  • 0

In our Rails app environment (ruby 1.8.7 / rails 2.3.12) I can run the following code:

class MongoTester
  include MongoMapper::Document
  key :test_arr, Array, :default => []
end

mt = MongoTester.new
mt.test_arr << 24

mt2 = MongoTester.new

The output of mt2.inspect is:

 #<MongoTester test_arr: [24], _id: BSON::ObjectId('4e5c089f3beaacad00000002')>

I’m not sure how this is possible. object_id and _id for both records are different. Neither one is saved. We haven’t modified MongoMapper in our application (mongomapper 0.8.6). Yet a completely new record contains the data of a previously created different record.

I can’t reproduce this in MongoMapper’s test suite.

Any information on how this effect is possible or how I can get rid of it would be awesome. Thanks!

  • 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-05-25T03:20:31+00:00Added an answer on May 25, 2026 at 3:20 am

    That is a bug: file it at https://github.com/jnunemaker/mongomapper/issues/new This bug is fixed in newer versions of MongoMapper

    Here’s a workaround:

    key :test_arr, Array, :default => lambda { [] }

    It’s because arrays in Ruby are mutable, so your default array object is getting added to each time with <<. The object_id’s of your docs will be different, but the object_id’s of the arrays will be the same.

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

Sidebar

Related Questions

How can I deploy my Ruby-on-Rails app to a Staging environment on EngineYard and
Some of the users of our Ruby on Rails app have complained that page
Our rails app is designed as a single code base linking to multiple client
I'm using pagination on our Ruby on Rails app and the pages are defined
Our rails app runs on a ubuntu 10.04 server with sqlite3 database. How can
We are getting close to releasing our new rails app and so far interest
I'm looking into database backup options for our Heroku rails app, and it looks
We just upgraded our app to Rails 3.2.2 and are now having a routing
We're using EngineYard Cloud to deploy our Ruby on Rails application. We are running
We use the wonderful semantic versioning paradigm when versioning our rails app. One question

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.