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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:22:48+00:00 2026-05-13T20:22:48+00:00

Do you have any insights into the most elegant way of persisting objects from

  • 0

Do you have any insights into the most elegant way of persisting objects from a dynamic language in a document database?

I have a solid background in C# and have just started programming in Python. At the same time I am trying to learn the ropes of MongoDB.

Now I am wondering: what is the most elegant way to persist my data to the MongoDB database? I have considered several approaches:

  1. Make all my Python classes able to create a graph of dictionaries and lists representing their state. Moreover, make them able to initialize their state from such a graph. When I want to persist an object, I will ask it for its graph representation and persist that. When I want to get an object, I will retrieve a document graph and provide this to the __init__ method of my class.

  2. Create a separate Mapper class capable of inspecting a given object and creating a graph of dictionaries and lists, which I may then store in MongoDB. The mapper would also be responsible for creating objects whose data has been retrieved from the database.

  3. I tried out mongoengine, a document-object mapper. However, I was disappointed when it forced me to derive my classes from a particular class (Document). It reminded me of Microsoft’s Entity Framework 1.0 and the lack of POCO support. I don’t want to be forced to derive from a particular class. It doesn’t feel right, but I am unsure whether this is really a problem in a dynamic language.

Is my thinking being hindered by my background in C#? I am sure I haven’t grokked the extent of the flexibility that a dynamic language provides, so any advice or hints at best practices would be greatly appreciated.

Thank you.

  • 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-13T20:22:48+00:00Added an answer on May 13, 2026 at 8:22 pm

    Python defines several special methods such as getstate and many others to allow your classes to define exactly how best to serialize and de-serialize their instances. They’re all used internally by the pickle module (which then uses this information to produce a “blob”, i.e. a string of bytes, and restore objects from such blobs), but, if you want better indexing obtained by storing graphs directly rather than via opaque blobs, it’s basically a question of tweaking the pickle procedures to stop just before turning the graphs into blobs. I think you’ll have to do it by copy-paste-edit of pickle.py (as it’s not designed to be customized in this way by more elegant methods such as subclassing), but that should still save you lots of work wrt redoing it all from scratch.

    I believe this approach lies somewhere between your options 1 and 2 — classes need to define such special methods only in response to specific needs, and most of the work needed to orchestrate the various possibility will be handled by your pickle-variant (much as it’s handled by pickle itself for the “normal” case where the serialized form is a blob).

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

Sidebar

Related Questions

I wonder if anyone has any insights into this. I have a bash script
Does anyone have any insights into when/under what conditions applicationWillTerminate is called in iOS
Anyone have any ideas on a good way to model the following scenario in
I'm trying to determine what is the most efficient way to load videos into
I have created an application that will be importing CSV files into a database
Does anyone has any insight on organizing sqlalchemy based projects? I have many tables
Anyone have any idea why my jQuery carousel is working fine at the bottom
Anyone have any experience yet getting Radiant CMS extensions to actually make it onto
Anyone have any ideas what I can do? Please reserve commenting about using 1.1
Anyone have any idea how to connect to their FTP server? I am using

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.