Error: ObjectIDs must be exactly 12 bytes long (got 0)

4,675 views
Skip to first unread message

Ruslan Mezentsev

unread,
Apr 7, 2012, 2:08:24 PM4/7/12
to mgo-users
Hi, how to fix the error?
Code: https://gist.github.com/2330858
MongoDB: mongodb 2.0.4 with a flag V8
OS: Gentoo amd64
Go: Go1

rmib@rsunix ~/docs/develop/web $ ./bin/web
ObjectIdHex("4f807e48c2be8935f5000001")
----------------------
Error: ObjectIDs must be exactly 12 bytes long (got 0)
----------------------
2012/04/07 23:50:01 http: panic serving 127.0.0.1:53378: ObjectIDs
must be exactly 12 bytes long (got 0)
/home/rmib/docs/develop/go/src/pkg/net/http/server.go:576 (0x45c6bd)
_func_003: buf.Write(debug.Stack())
/home/rmib/docs/develop/go/src/pkg/runtime/proc.c:1443 (0x410f33)
panic: reflect·call(d->fn, d->args, d->siz);
/home/rmib/docs/develop/web/src/web/main.go:23 (0x400c4e)
check: panic(err)
/home/rmib/docs/develop/web/src/web/main.go:70 (0x401391)
NewArticle: check(err)
/home/rmib/docs/develop/web/src/web/main.go:79 (0x4014aa)
serveAuth: NewArticle("test", "test", "test","test",
[]string{"Test"})
/home/rmib/docs/develop/go/src/pkg/net/http/server.go:690 (0x450722)
HandlerFunc.ServeHTTP: f(w, r)
/home/rmib/docs/develop/go/src/pkg/net/http/server.go:924 (0x4515a4)
(*ServeMux).ServeHTTP: mux.handler(r).ServeHTTP(w, r)
/home/rmib/docs/develop/go/src/pkg/net/http/server.go:656 (0x450535)
(*conn).serve: handler.ServeHTTP(w, w.req)
/home/rmib/docs/develop/go/src/pkg/runtime/proc.c:271 (0x40f039)
goexit: runtime·goexit(void)

Gustavo Niemeyer

unread,
Apr 7, 2012, 2:24:34 PM4/7/12
to mgo-...@googlegroups.com
Hi there,

On Sat, Apr 7, 2012 at 15:08, Ruslan Mezentsev <rmib....@gmail.com> wrote:
> Hi, how to fix the error?

(...)


> rmib@rsunix ~/docs/develop/web $ ./bin/web
> ObjectIdHex("4f807e48c2be8935f5000001")

That's not the ObjectId it's complaining about. You have a second one
on Commentaries. Either initialize it, or use `bson:",omitempty"` in
the tag so that it's not sent.

--
Gustavo Niemeyer
http://niemeyer.net
http://niemeyer.net/plus
http://niemeyer.net/twitter
http://niemeyer.net/blog

-- I'm not absolutely sure of anything.

Ruslan Mezentsev

unread,
Apr 7, 2012, 2:51:42 PM4/7/12
to mgo-users
Thanks, my mistake, but I looking for a long time)

On 8 апр, 00:24, Gustavo Niemeyer <gust...@niemeyer.net> wrote:
> Hi there,
>
>
>
> On Sat, Apr 7, 2012 at 15:08, Ruslan Mezentsev <rmib.em...@gmail.com> wrote:
> > Hi, how to fix the error?
> (...)
> > rmib@rsunix ~/docs/develop/web $ ./bin/web
> > ObjectIdHex("4f807e48c2be8935f5000001")
>
> That's not the ObjectId it's complaining about. You have a second one
> on Commentaries. Either initialize it, or use `bson:",omitempty"` in
> the tag so that it's not sent.
>
> --
> Gustavo Niemeyerhttp://niemeyer.nethttp://niemeyer.net/plushttp://niemeyer.net/twitterhttp://niemeyer.net/blog

qiao deng

unread,
Jan 22, 2014, 10:27:34 PM1/22/14
to mgo-...@googlegroups.com
how about  if ObjectId.valid() return false mgo just ignore it  except _id field ,I think this should be default behavior

在 2012年4月8日星期日UTC+8上午2时24分34秒,Gustavo Niemeyer写道:

Gustavo Niemeyer

unread,
Jan 24, 2014, 7:11:31 AM1/24/14
to mgo-...@googlegroups.com
Hi Qiao,

On Thu, Jan 23, 2014 at 1:27 AM, qiao deng <dengqi...@gmail.com> wrote:
> how about if ObjectId.valid() return false mgo just ignore it except _id
> field ,I think this should be default behavior

You mean accepting corrupted ObjectId values as if they were empty?
That doesn't sound like a good idea.


gustavo @ http://niemeyer.net

nikos efthias

unread,
May 27, 2017, 7:25:16 PM5/27/17
to mgo-users
it clearly says (Got 0) so how come it is corrupted its just empty i have very same situation 

type User struct {
Id bson.ObjectId `json:"_id,omitempty"bson:"_id,omitempty"`
Name string `json:"name"bson:"name,omitempty"`
Surname string `json:"surname"bson:"surname,omitempty"`
ProfilePicture string `json:"profile_picture"bson:"profile_picture"`
Username string `json:"username,omitempty"bson:"username,omitempty"`
Email string `json:"email"bson:"email"`
Password string `json:"-"bson:"password,omitempty"`
}

And when i create a `new(User)` and try to edit something and then insert i get the same error though i never touched the objectid and i set it to omitempty

Gustavo Niemeyer

unread,
May 27, 2017, 11:15:29 PM5/27/17
to mgo-...@googlegroups.com
Hi Nikos,

I'm responding it in the issue you've reported:

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages