Skip to content

Instantly share code, notes, and snippets.

@rothwerx
Created April 26, 2013 20:44
Show Gist options
  • Save rothwerx/5470311 to your computer and use it in GitHub Desktop.
Save rothwerx/5470311 to your computer and use it in GitHub Desktop.
Perl: MongoDB update
sub update_mongodb {
if (!Opts::option_is_set('noupdate')) {
my $client = MongoDB::MongoClient->new(host => $mongohost, port => $mongoport);
my $database = $client->get_database( $mongodatabase );
my $db = $database->get_collection( $mongocollection );
my $mongohash = \%hosthash;
my $mongoresult = $db->update({ "hostname" => $hosthash{'hostname'} }, $mongohash, { "upsert" => 1} );
print $mongoresult;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment