snowtty 发表于 2011-12-23 02:11

use MongoDB::OID;

<DIV>#!/usr/bin/perl</DIV>
<DIV>use warnings;<BR>use strict;</DIV>
<DIV>use Data::Dumper;</DIV>
<DIV>use MongoDB;<BR>use MongoDB::OID;</DIV>
<DIV>my $con = MongoDB::Connection-&gt;new;</DIV>
<DIV>my $db = $con-&gt;syncrobid;</DIV>
<DIV>my $account_col = $db-&gt;account;</DIV>
<DIV>$account_col-&gt;remove;</DIV>
<DIV>my $account_data = {</DIV>
<DIV>&nbsp;# _id will be created automatically</DIV>
<DIV>&nbsp;company_name =&gt; '',<BR>&nbsp;username =&gt; '',</DIV>
<DIV>&nbsp;subscription_id =&gt; '', # used for Authorize.net</DIV>
<DIV>&nbsp;fax =&gt; '',<BR>&nbsp;phone =&gt; '',</DIV>
<DIV>&nbsp;address =&gt; {<BR>&nbsp;&nbsp;street =&gt; '',<BR>&nbsp;&nbsp;city =&gt; '',<BR>&nbsp;&nbsp;state =&gt; '',<BR>&nbsp;&nbsp;zip =&gt; ''<BR>&nbsp;},</DIV>
<DIV>&nbsp;users =&gt; [<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;_id =&gt; MongoDB::OID-&gt;new,</DIV>
<DIV>&nbsp;&nbsp;&nbsp;f_name =&gt; '',<BR>&nbsp;&nbsp;&nbsp;l_name =&gt; '',<BR>&nbsp;&nbsp;&nbsp;phone =&gt; '',<BR>&nbsp;&nbsp;&nbsp;ext =&gt; '',<BR>&nbsp;&nbsp;&nbsp;mobile =&gt; '',<BR>&nbsp;&nbsp;&nbsp;email =&gt; '',<BR>&nbsp;&nbsp;&nbsp;tasks =&gt; [ '', '', '' ],</DIV>
<DIV>&nbsp;&nbsp;&nbsp;settings =&gt; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;admin =&gt; 1,<BR>&nbsp;&nbsp;&nbsp;&nbsp;block_email =&gt; 1<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;],</DIV>
<DIV>&nbsp;projects =&gt; [<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;_id =&gt; MongoDB::OID-&gt;new,<BR>&nbsp;&nbsp;&nbsp;name =&gt; '',<BR>&nbsp;&nbsp;&nbsp;area =&gt; '',<BR>&nbsp;&nbsp;&nbsp;union_status =&gt; '',<BR>&nbsp;&nbsp;&nbsp;users =&gt; [], # Like a has_many relationship, retrieve to get a list of users ids that are working on this current project<BR>&nbsp;&nbsp;&nbsp;task =&gt; [ qw// ],<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;revision =&gt; [<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_id =&gt; MongoDB::OID-&gt;new,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name =&gt; '',<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;due_date =&gt; DateTime-&gt;now,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;created_timestamp =&gt; DateTime-&gt;now,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;files =&gt; [ qw// ]<BR>&nbsp;&nbsp;&nbsp;&nbsp;},<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_id =&gt; MongoDB::OID-&gt;new,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name =&gt; '',<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;due_date =&gt; DateTime-&gt;now,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;created_timestamp =&gt; DateTime-&gt;now,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;files =&gt; [ qw// ]<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;],</DIV>
<DIV>&nbsp;&nbsp;&nbsp;settings =&gt; { # these settings override global settings<BR>&nbsp;&nbsp;&nbsp;&nbsp;auto_release_plans =&gt; 1<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;],</DIV>
<DIV>&nbsp;gallery =&gt; [<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;_id =&gt; MongoDB::OID-&gt;new,<BR>&nbsp;&nbsp;&nbsp;project_name =&gt; '',<BR>&nbsp;&nbsp;&nbsp;location =&gt; '',<BR>&nbsp;&nbsp;&nbsp;comments =&gt; [ qw// ]<BR>&nbsp;&nbsp;},<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;_id =&gt; MongoDB::OID-&gt;new,<BR>&nbsp;&nbsp;&nbsp;project_name =&gt; '',<BR>&nbsp;&nbsp;&nbsp;location =&gt; ''<BR>&nbsp;&nbsp;}<BR>&nbsp;],</DIV>
<DIV>&nbsp;settings =&gt; { # Set per account_type<BR>&nbsp;&nbsp;auto_release_plans =&gt; 1,<BR>&nbsp;&nbsp;hide_general_email =&gt; 1<BR>&nbsp;}<BR>};</DIV>
<DIV>my $account_id = $account_col-&gt;insert( $account_data );</DIV>
<DIV>print Dumper( $account_col-&gt;find_one({ "_id" =&gt; $account_id }) );<BR></DIV>
页: [1]
查看完整版本: use MongoDB::OID;