在mongoDB中插入数组类型对象

时间:2015-04-21 10:41:03

标签: node.js mongodb

我正在尝试使用mongoDB shell将对象数组添加到我的数据库中。我收到"SyntaxError: Unexpected String"错误。

代码

db.Tests.insert(
    {
        "id": "chapter1"
        "questions": [
            {
                "questionID": "1",
                "question": "How much is 1+1",
                "Answer1": "1",
                "Answer2": "2",
                "Answer3": "3",
                "Answer4": "4",
                "CorrectAns": "2"
            } 
        ]
    }
)

1 个答案:

答案 0 :(得分:0)

db.Tests.insert(
    {
        "id": "chapter1", // <=== here is the bug
        "questions": [
            {
                "questionID": "1",
                "question": "How much is 1+1",
                "Answer1": "1",
                "Answer2": "2",
                "Answer3": "3",
                "Answer4": "4",
                "CorrectAns": "2"
            } 
        ]
    }
)