0

Portfolio class has an array field named folders. when i create it using :

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}
    ]}
])

I got error that "SyntaxError: missing ) after argument list (shell):1". Any guesses?

3
  • you have to wrap folders: [...] You can't do insert(x:[]), it must be insert({x:[]}) Commented Aug 13, 2013 at 6:04
  • If i do this i got error Syntax error missing id 1 Commented Aug 13, 2013 at 6:12
  • Use : instead of => and wrap folders into {}`. Commented Aug 13, 2013 at 6:34

1 Answer 1

1

This will work:

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}
    ]}
]})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.