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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:40:11+00:00 2026-05-27T07:40:11+00:00

I use mongoengine for mongodb in django. but.. mongoengine fields (like StringField) makes me

  • 0

I use mongoengine for mongodb in django.

but.. mongoengine fields (like StringField) makes me build up schema toward the way that I don’t want. I mean, it strictly insists that I pre-write key name before I do know what it will be. for example…

in case that I do not know what key name will be put into database…

> for(var i=0; i<10; i++){
... o = {};
... o[i.toString()] = i + 100;
... db.test.save(o)
... }
> db.test.find()
{ "_id" : ObjectId("4ed623aa45c8729573313811"), "0" : 100 }
{ "_id" : ObjectId("4ed623aa45c8729573313812"), "1" : 101 }
{ "_id" : ObjectId("4ed623aa45c8729573313813"), "2" : 102 }
{ "_id" : ObjectId("4ed623aa45c8729573313814"), "3" : 103 }
{ "_id" : ObjectId("4ed623aa45c8729573313815"), "4" : 104 }
{ "_id" : ObjectId("4ed623aa45c8729573313816"), "5" : 105 }
{ "_id" : ObjectId("4ed623aa45c8729573313817"), "6" : 106 }
{ "_id" : ObjectId("4ed623aa45c8729573313818"), "7" : 107 }
{ "_id" : ObjectId("4ed623aa45c8729573313819"), "8" : 108 }
{ "_id" : ObjectId("4ed623aa45c872957331381a"), "9" : 109 }

[addition]

as you can see above, key is very different from each other..
just assume that “I do not know what key name will be put into document as key ahead of time

as dcrosta replied.. I am looking for a way to use mongoengine without specifying the fields ahead of time.

[/addition]

How can I do the same thing through mongoengine?
please give me schema design like

class Test(Document):
    tag = StringField(db_field='xxxx')

[addition]

I don’t know what ‘xxxx’ will be as key name.

sorry.. I’m Korean so my english is awkward.
please give me your some knowledge.
Thanks for reading this.

[/addition]

  • 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-27T07:40:12+00:00Added an answer on May 27, 2026 at 7:40 am

    Have you considered using PyMongo directly instead of using Mongoengine? Mongoengine is designed to declare and validate a schema for your documents, and provides many tools and conveniences around that. If your documents are going to vary, I’m not sure Mongoengine is the right choice for you.

    If, however, you have some fields in common across all documents, and then each document has some set of fields specific to itself, you can use Mongoengine’s DictField. The downside of this is that the keys will not be “top-level”, for instance:

    class UserThings(Document):
        # you can look this document up by username
        username = StringField()
    
        # you can store whatever you want here
        things = DictField()
    
    dcrosta_things = UserThings(username='dcrosta')
    dcrosta_things.things['foo'] = 'bar'
    dcrosta_things.things['bad'] = 'quack'
    dcrosta_things.save()
    

    Results in a MongoDB document like:

    { _id: ObjectId(...),
      _types: ["UserThings"],
      _cls: "UserThings",
      username: "dcrosta",
      things: {
        foo: "bar",
        baz: "quack"
      }
    }
    

    Edit: I should also note, there’s work in progress on the development branch of Mongoengine for “dynamic” documents, where attributes on the Python document instances will be saved when the model is saved. See https://github.com/hmarr/mongoengine/pull/112 for details and history.

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

Sidebar

Related Questions

I'm trying to use django, and mongoengine to provide the storage backend only with
use this website a lot but first time posting. My program creates a number
We use a data acquisition card to take readings from a device that increases
I have django installed on my server with pymongo and mongoengine.My django project settings.py
Use scenario is pretty simple: I have a desktop only application that could be
I am trying out MongoEngine , a DRM library for Python to use with
use case example I have a servlet that is receiving login requests. If a
Use MongoDB GridFS store images and images stored directly on disk What are the
Use Html element SELECT in aspx page like: <SELECT id=MySelection name=MySelection runat=server DataValueField=ID DataTextField=Name></SELECT>
For one of my projects I prefered using Django+Mongo . Why should I use

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.