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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:27:51+00:00 2026-05-26T20:27:51+00:00

I have a MongoMapper model called LogInfo that has a number of fields already

  • 0

I have a MongoMapper model called LogInfo that has a number of fields already defined (:user_id, :user_key, :message, etc)

However, I’d also like the user to embed their own JSON objects as an EmbeddedDocument.

Is there a way to use anonymous objects to create a custom object in MongoMapper? Would I have to resort to the native Ruby driver instead? The final object would look something like this:

{
    user_id: 393,
    user_key: "kdIekHG32Je",
    message: "Application error",
    custom_data: {
        browser: "Firefox 8.0",
        location: {
             lat: 34.323,
             lon: -14.091
        }
    }
}

where the custom_data field is something random the app user can provide.

  • 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-26T20:27:52+00:00Added an answer on May 26, 2026 at 8:27 pm

    Sure. You don’t have to resort to the Ruby driver.

    MongoMapper turns objects into a MongoDB representation by calling:

    ObjectClass.to_mongo(object_instance)
    

    The to_mongo method is already defined for a bunch of standard classes, and you can define it for your own classes too. See lib/mongo_mapper/extensions for all the classes that have to_mongo defined and http://mongomapper.com/documentation/types.html for the documentation on custom types.

    BUT, if you’re content to let your users just hand you a hash, it’ll just work.

    class LogEntry
      include MongoMapper::Document
      key :custom_data, Hash
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MongoMapper model and am trying to convert a comma-delimited string into
I have a Rails 3 model D that belongs to another model, which belongs
I run a sinatra application with mongomapper. I have models called Movie(Document) and Cover(EmbeddedDocument).
I have an application that in uploading files to GridFS via MongoMapper/Joint in Padrino.
I am using Rails with MongoDB and MongoMapper. My problem is that I have
I have a Record model (Active Record) that stores some custom logs. Record is
I have a trip model that contains an array of lat/lng pairs class Trip
Lets say we have a simple model that stores two integers, the min and
Have you determined a maximum number of characters allowed in FCKEditor ? I seem
I have a rails app where i have a Contact model and with an

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.