Want to add nested data into mongoDB ,i am working in django,i have tried both the foreign key and EmbedField but unable to get nested data into DB
i am working in django,i have tried both the foreign key and EmbedField but unable to get nested data into mongoDB,when run migrations i created two models in mongoDB, my models are
class Employee(models.Model):
id=models.ObjectIdField()
name = models.CharField(max_length=255)
age = models.IntegerField()
email=models.EmailField()
phone_number=models.CharField(max_length=20)
def __str__(self) -> str:
return self.name
class Company(models.Model):
name = models.CharField(max_length=255)
description = models.TextField()
location = models.CharField(max_length=255)
email=models.EmailField()
employees = models.ArrayField(
model_container=Employee,
null=True,
blank=True,
)
def __str__(self):
return self.name
and the data i am getting in Company collection is like {
"_id": {
"$oid": "66c8b0c7fc77e7422da0e80d"
},
"id": 2,
"name": "dgdhg",
"description": "abhdj",
"location": "sdsgh",
"email": "xeno@gmail.com"
}