Is there a way to detect a dup key error when inserting documents to shard?

548 views
Skip to first unread message

Feng Liyuan

unread,
Jan 13, 2014, 4:54:38 AM1/13/14
to mgo-...@googlegroups.com
I inserted a duplicate key into shard and got an error, but IsDup(err) function could not perform correctly.
I printed the error
&mgo.LastError{
    Err:"error inserting 1 documents to shard ro_s_1_6:ro_s_1_6/192.168.1.221:27018,192.168.1.222:27018 at version 6|115||52c1171d330bbae1e42d97c5 :: caused by :: E11000 duplicate key error index: ro_s_1.rs.$_id_  dup key: { : \"77g1ej:\" }",
    Code:16460,
    N:0,
    Waited:0,
    FSyncFiles:0,
    WTimeout:false,
    UpdatedExisting:false,
    UpsertedId:interface {}(nil)
}
The code is 16460, not 11000 11001 12582. I searched this code it says that's an error inserting documents to shard.

Gustavo Niemeyer

unread,
Jan 13, 2014, 6:50:09 AM1/13/14
to mgo-...@googlegroups.com
Thanks for the report. I'll enhance the IsDup function to catch these cases too.

Sorry for the trouble.
> --
> You received this message because you are subscribed to the Google Groups
> "mgo-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mgo-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.



--

gustavo @ http://niemeyer.net

Feng Liyuan

unread,
Jan 13, 2014, 8:59:34 PM1/13/14
to mgo-...@googlegroups.com
Thanks for your quick reply. Hope to see your update.

Feng Liyuan

unread,
Jan 16, 2014, 6:23:42 AM1/16/14
to mgo-...@googlegroups.com
Hi, sorry to bother u again.
Do u have any clue to deal with this issue, or anything I can do to workaround it? Our mongo will be full soon, so we really need this feature for shard.


On Monday, January 13, 2014 7:50:09 PM UTC+8, Gustavo Niemeyer wrote:

Gustavo Niemeyer

unread,
Jan 16, 2014, 6:39:38 AM1/16/14
to mgo-...@googlegroups.com
To workaround the issue sooner, just check the error yourself:

if lerr, ok := err.(*mgo.LastError); ok && lerr.Code == 16460 &&
strings.Contains(lerr.Err, " E11000 ") {
// ... key is duplicated in a shard.
Reply all
Reply to author
Forward
0 new messages