0

投资组合类有一个名为文件夹的数组字段。当我使用以下方法创建它时:

db.portfolio.insert(
  folders: [
    {"name"=>"Folder 1", 
     "stocks"=>[
        {"name"=>"stock name", 
         "id"=>"stock id1", 
         "qty"=>2},
        {"name"=>"stock name",
         "id"=>"stock id2",
         "qty"=>1}
    ]},
    {"name"=>"Folder 2",
     "stocks"=>[
        {"name"=>"stock name",
         "id"=>"stock id3",
         "qty"=>2},
        {"name"=>"stock name",
         "id"=>"stock id4",
         "qty"=>1}
    ]}
])

我在参数列表(shell):1 之后收到错误“SyntaxError:missing”。有什么猜测吗?

4

1 回答 1

1

这将起作用:

db.portfolio.insert({
  folders: [
    {"name":"Folder 1", 
     "stocks":[
        {"name":"stock name", 
         "id":"stock id1", 
         "qty":2},
        {"name":"stock name",
         "id":"stock id2",
         "qty":1}
    ]},
    {"name":"Folder 2",
     "stocks":[
        {"name":"stock name",
         "id":"stock id3",
         "qty":2},
        {"name":"stock name",
         "id":"stock id4",
         "qty":1}
    ]}
]})
于 2013-08-13T06:35:11.403 回答