I am getting payload which included key like
{
"id": UUID,
"phone_number": "+141 98324 2434",
"organization": "xyz",
"property":{
"name": "abc",
"email": "xyz",
"address": {
"street": "6th St",
"city": "San Francisco",
"state": "CA",
"postalCode": "94103",
"country": "USA"
},
"age":14,
}
}
my model looks like this:
from jsonfield import JSONField
organization = models.ForeignKey(Organization, on_delete=models.DO_NOTHING)
phone_number = models.CharField(max_length=16, unique=True, db_index=True)
tags = models.TextField(blank=True, null=True)
property = JSONField(default={}, blank=True, null=True)
Now while storing property(its dynamic) in my djongo DB, i want it to save as object(dict) data type so that later i can query using customer.object.filter(property__age=14).
Right now its getting stored as string hence i m not able to query my property field.
here is some what is looks like in mongodb.
id: UUID
phone_numer: "xyz"
organization: "xyz"
property:"{"name":"abc","age":14}"
How should i store property as object in mongodb?