Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hello andal,

I have never used MongoDB and you have not provided us with a minimum example problem replication code to play around so I will just provide you some possible solutions until further update.

Possible solution 1 from (MongoDB::Tutorial):

$users->insert_one( { "name" => "Joe", "age" => 52, "likes" => [qw/skiing math ponies/] });

Possible solution 2 from (MongoDB::Examples):

$db->get_collection( 'users' )->insert_one( { a => 1, b => 1 } );

If none of the examples work in your case, please provide us with minimal working example code that replicates your problem and me and all other monks will be more than happy to help you as much as possible.

Update: regarding the MongoDB::WriteConcern it is defined like this:

$rp = MongoDB::WriteConcern->new(); # w:1, wtimeout: 1000 $rp = MongoDB::WriteConcern->new( w => 'majority', wtimeout => 10000, # milliseconds );

Update2: reading through the MongoDB::Collection and based on your sample of code you are interested in capturing the error on insert_one(). If so it can be done like this:

use Try::Tiny; use Safe::Isa; # provides $_isa try { $coll->insert_one( $doc ) } catch { if ( $_->$_isa("MongoDB::DuplicateKeyError" ) { ... } else { ... } };

Update3: reading through the MongoDB::MongoClient and based on the documentation you could use write_concern, from the documentation:

Returns a MongoDB::WriteConcern object constructed from "w", "write_co +ncern" and "j".

Also from the same module MongoDB::MongoClient you could use $coll->insert() sample of code:

$coll->insert({ name => "John Doe", age => 42 });

Hope this helps.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: MongoDB and WriteConcern by thanos1983
in thread MongoDB and WriteConcern by andal

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2023-06-07 02:13 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (29 votes). Check out past polls.