Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb remove fails on "invalid object id"

I'm trying to delete documents using MongoDB shell, but for some reason it keeps failing on "invalid object id: length"

query:

db.collections.remove( { _id : ObjectId("FF125DF6-E977-404A-9E8C-600CDAFEFF53" )} );

error:

Mon Dec 24 03:11:15 Assertion: 10448:invalid object id: length 0x6073f1 0x5d1aa9 0x5ac3f1 0x5b84f4 0x6aa5ac 0x6aaec8 0x69e4e7 0x6aa13f 0x668e46 0x668ec2 0x66a2ce 0x5cbcc4 0x4a44a6 0x4a67e6 0x7f2554e2fcdd 0x49f669 mongo(_ZN5mongo15printStackTraceERSo+0x21) [0x6073f1] mongo(_ZN5mongo11msgassertedEiPKc+0x99) [0x5d1aa9] mongo() [0x5ac3f1] mongo(_ZN5mongo21object_id_constructorEP9JSContextP8JSObjectjPlS4_+0x2b4) [0x5b84f4] mongo(js_Invoke+0x40c) [0x6aa5ac] mongo(js_InvokeConstructor+0x108) [0x6aaec8] mongo(js_Interpret+0x37c7) [0x69e4e7] mongo(js_Execute+0x36f) [0x6aa13f] mongo(JS_EvaluateUCScriptForPrincipals+0x66) [0x668e46] mongo(JS_EvaluateUCScript+0x22) [0x668ec2] mongo(JS_EvaluateScript+0x6e) [0x66a2ce] mongo(_ZN5mongo7SMScope4execERKNS_10StringDataERKSsbbbi+0x144) [0x5cbcc4] mongo(_Z5_mainiPPc+0x2156) [0x4a44a6] mongo(main+0x26) [0x4a67e6] /lib64/libc.so.6(__libc_start_main+0xfd) [0x7f2554e2fcdd] mongo(__gxx_personality_v0+0x2a1) [0x49f669] Mon Dec 24 03:11:15 Error: invalid object id: length (shell):1

I tried running

db.repairDatabase();

but nothing is changed. from checking around i see that its a known issue,is there a workaround for this?

EDIT

here is the document as it is in the db:

{

"_id": "FF125DF6-E977-404A-9E8C-600CDAFEFF53",

"data": {

   "files": [
   ],

   "categories": [
  ],

   "trash": [
   ]
 }

}

Thanks!

like image 325
avital Avatar asked Dec 24 '12 08:12

avital


1 Answers

ObjectId("FF125DF6-E977-404A-9E8C-600CDAFEFF53") is invalid. ObjectId is 12-byte BSON type and could not have '-' inside. Check the source where you get this id.

like image 80
coderLMN Avatar answered Sep 23 '22 23:09

coderLMN