mongoid3 - Array Creation array in mongodb -


portfolio class has array field named folders. when create 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 "syntaxerror: missing ) after argument list (shell):1". guesses?

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

Comments

Popular posts from this blog

vb.net - Alternative to the T-SQL AS keyword -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

ios - CFRelease causing crash in iPad application -