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