title: Perl and MongoDB: Inserting Array of Objects into Key-Value Pairs
body: <p>I'd like to insert into my MongoDB using perl the following BSON structure:</p>
  
  <pre><code>{"name" : "BOB", "stuff" : [{"area1": [1,2,3,4,5]}, {"area2": [5,6,7,8,9]}]}
  </code></pre>
  
  <p>But have had a hard time finding a good example of this. I tried the following:</p>
  
  <pre><code>#!/usr/bin/perl
  use MongoDB;
  use MongoDB::Database;
  use MongoDB::OID;
  
  my $conn = MongoDB::Connection-&gt;new;
  my $db = $conn-&gt;test;
  my $users = $db-&gt;real_time10;
  
  
  $users-&gt;insert
  ({
      "name" =&gt; "BOB",
      "stuff" =&gt; 
                "area1" =&gt; [1,2,3,4,5],
                "area2" =&gt; [5,6,7,8,9]
  });
  </code></pre>
  
  <p>Which grossly outputs upon query in the mongo shell:</p>
  
  <blockquote>
    <p>db.real_time10.find()</p>
  </blockquote>
  
  <pre><code>{ "_id" : ObjectId("4fc912fa000207ec08000000"), "ARRAY(0xa5bdd4)" : "area2", "A
  RAY(0x2f2e844)" : null, "name" : "BOB", "stuff" : "area1" }
  </code></pre>
  
  <p>What is going on? Is there a simple way to do this?</p>
  
  <p>My dream/desired output would be:</p>
  
  <pre><code>&gt; db.real_time10.find()
  
  { "_id" : ObjectId("4fc912fa000207ec08000000"), "stuff" : {"area1" : [1,2,3,4,5],   
  "area2": [5,6,7,8,9]}, "name" : "BOB" }
  </code></pre>