2015-09-05 66 views
0

我想將C struct作爲文檔的一部分存儲到MongoDB數據庫中。將C結構存儲到MongoDB中

例如,結構是這樣的:

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

我想在JSON文件中添加兩個字段。一個字段將是唯一的ID,第二個字段將在填充結構(學生數據)之上。

您能否引導我將上述JSON文檔存儲到MongoDB數據庫中?

回答

0

我對MongoDB一無所知,但是這裏有一個可以工作的JSON結構。 item.id,item.student.employee,item.student.name等。您可以過濾輸入以跟蹤數據類型。我不知道Mongo是否允許對JSON進行約束。

{ 
    "id": 999, 
    "student" : { 
    "employee": 0, 
    "name": "John Doe", 
    "status": 0, 
    "totmarks": 0 
    } 
}