Search code examples
pythonmongodbdjango-nonrelbson

django-nonrel specify MongoDB BSON element name to model attributes


In C# it is possible to use the MongoDB driver to define a custom BSONElement Name to each attribute in your data models, in order to shorten its stored name, such as

[BsonElement("c")]
public Boolean Current { get; set; }

Is there any way to accomplish this with a django-nonrel setup and a model defined like

class Test(models.Model):
    Current = models.BooleanField()

so that the attribute "Current" will be stored as "c" and be referenced in code as "Current"? Research did not work very well on this one.


Solution

  • Try setting the db_column option to BooleanField, or any field -- that should be the actual field name stored in MongoDB.