Perl MongoDB insert error msg
mongodb, perl
Solution
MongoDB::Collection::insert does not check for errors.
Try
my $enter = $db->data->insert({'user'=>'test','password'=>'test'}, {safe => 1});
to make the module croak on failure. This is documented in MongoDB::Collection
If you want to check for errors you can also do
my $error = $db->last_error();
as documented here.
Problem
I have this following database this is an object already in the database ``` { "_id" : ObjectId("001"), "password" : "test", "user" : "test"} ``` Things add to that collection 1.index over user and password 2.Unique index over user When i try to inssert the same parameters into the items ``` my $enter = $db->data->insert({'user'=>'test','password'=>'test'}); ``` $enter returns a value of a ObjectID(if user is repeated it should get a error msg rather than a Objectid) Through mongo shell E11000 duplicate key error index: dataofitem.user its showing error but when i try through Perl module (https://metacpan.org/module/MongoDB) it was returned as an object id, i was wondering why i did't got the error msg instead of Objectid