0

I would like to store C struct as a part of document into MongoDB database.

For example, struct looks like:

typedef struct student
{
    int employee;
    char name[50];
    unsigned char status;
    int totmarks;       
}

I would like to add two fields in the JSON document. One field would be unique ID and second field would be above filled structure(student data).

Can you please guide me in storing the above JSON document into MongoDB database?

mmking
  • 1,564
  • 4
  • 26
  • 36
Dayakar
  • 11
  • 2

1 Answers1

0

I don't know anything about MongoDB but here's a JSON structure that will work. item.id, item.student.employee, item.student.name, etc. You can filter your inputs to follow your data types. I don't know if Mongo allows for constraints on the JSON.

{
  "id": 999,
  "student" : {
    "employee": 0,
    "name": "John Doe",
    "status": 0,
    "totmarks": 0
  }
}
wolfhammer
  • 2,641
  • 1
  • 12
  • 11