Perl MongoDB insert msg error

I have the following database, this is an object already in the database

{ "_id" : ObjectId("001"), "password" : "test", "user" : "test"}

Adds to this collection

1.index over user and password

2.Universal index over user

When I try to include the same parameters in elements

my $enter = $db->data->insert({'user'=>'test','password'=>'test'});

$ enter returns the ObjectID value (if the user is repeated, he should receive the msg error message, not Objectid)

Through the shell of a mango

E11000 Repeating Key Error Index: dataofitem.user

shows my error, but when I try to use the Perl module ( https://metacpan.org/module/MongoDB )

it was returned as the identifier of the object, I was wondering why I did not get the msg error instead of Objectid

+3
source share
1 answer

MongoDB:: Collection:: insert .

Try

my $enter = $db->data->insert({'user'=>'test','password'=>'test'}, {safe => 1});

. MongoDB:: Collection

,

my $error = $db->last_error();

.

+5

All Articles