Announcing mgo r2011.08.02

62 views
Skip to first unread message

Gustavo Niemeyer

unread,
Aug 2, 2011, 9:03:49 PM8/2/11
to golan...@googlegroups.com, mongod...@googlegroups.com, mgo-...@googlegroups.com
Following the release r59 of Go, another quick update on the
mgo MongoDB driver for Go is available, including compatibility
fixes and a few additional goods.

The project page with details is available at:

http://labix.org/mgo

The following changes were made in release r2011.08.02.

- The tag format for marshalled fields has been changed to
follow the conventions established in release r59 of Go.
The key name within the tag is now separated from flags
using a comma, and flags have also been renamed.

Here is a simple table for migration:

"/c" => ",omitempty"
"/s" => ",minsize"
"/cs" => ",omitempty,minsize"
"key" => "key"
"key/c" => "key,omitempty"
"key/s" => "key,minsize"
"key/cs" => "key,omitempty,minsize"

If provided with an old-styled tag, gobson will panic
reporting the problem and will also inform the new
spelling for the specific tag at hand.

For more details, please see the documentation:

http://goneat.org/lp/gobson/bson#Marshal
http://goneat.org/lp/gobson/bson#Unmarshal

- The bson tag information can now be namespaced. For
example, the following is a valid tag with information for
both the json and the bson packages:

`bson:",omitempty" json:",omitempty"`

Using the bson namespace is optional as long as the
content of the tag, which should be fully oriented towards
gobson, does not contain the ":" character.

- To improve consistency in the naming convention, the recently
introduced GetRef methods have been renamed to FindRef, and
GetLiveServers was renamed to LiveServers:

http://goneat.org/lp/mgo#Session.FindRef
http://goneat.org/lp/mgo#Database.FindRef
http://goneat.org/lp/mgo#Session.LiveServers

- New ObjectId.Hex method to obtain the commonly wanted hex
representation of the id, as requested by Travis Reeder:

http://goneat.org/lp/gobson/bson#ObjectId.Hex

- ObjectId pointers may now be marshalled and unmarshalled
properly by the json package, also requested by Travis:

http://goneat.org/lp/gobson/bson#ObjectId.MarshalJSON
http://goneat.org/lp/gobson/bson#ObjectId.UnmarshalJSON

- New DatabaseNames and CollectionNames methods, as requested
by Fabian Reinartz:

http://goneat.org/lp/mgo#Session.DatabaseNames
http://goneat.org/lp/mgo#Database.CollectionNames

- New GridFile.UploadDate method, also requested by Fabian:

http://goneat.org/lp/mgo#GridFile.UploadDate


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

-- I never filed a patent.

Evan Shaw

unread,
Aug 18, 2011, 4:32:14 AM8/18/11
to mgo-...@googlegroups.com, mongod...@googlegroups.com
On Wed, Aug 3, 2011 at 1:03 PM, Gustavo Niemeyer <gus...@niemeyer.net> wrote:
> - ObjectId pointers may now be marshalled and unmarshalled
>  properly by the json package, also requested by Travis:
>
>      http://goneat.org/lp/gobson/bson#ObjectId.MarshalJSON
>      http://goneat.org/lp/gobson/bson#ObjectId.UnmarshalJSON

I've got one further request here. Can these methods have value
receivers instead of pointer receivers?

As it is, if I have a struct with an ObjectId field, json fails to
marshal unless I turn the field into a pointer, which I'd prefer not
to do. With that small change, json marshals both pointers and values
correctly. (I haven't tested unmarshalling yet, but I assume it has
the same problem.)

- Evan

Gustavo Niemeyer

unread,
Sep 14, 2011, 10:14:19 PM9/14/11
to mgo-...@googlegroups.com, mongod...@googlegroups.com
Hey Evan,

> I've got one further request here. Can these methods have value
> receivers instead of pointer receivers?
>
> As it is, if I have a struct with an ObjectId field, json fails to
> marshal unless I turn the field into a pointer, which I'd prefer not

I lost that request somehow when you mentioned it last month, but
looking over the list for pending things I got it, and will be in the
next release.

> to do. With that small change, json marshals both pointers and values
> correctly. (I haven't tested unmarshalling yet, but I assume it has
> the same problem.)

No, unmarshalling cannot change in that regard, otherwise we'd be
unable to set the id field to the unmarshalled value.

Evan Shaw

unread,
Sep 14, 2011, 10:31:51 PM9/14/11
to mgo-...@googlegroups.com
On Thu, Sep 15, 2011 at 2:14 PM, Gustavo Niemeyer <gus...@niemeyer.net> wrote:
> I lost that request somehow when you mentioned it last month, but
> looking over the list for pending things I got it, and will be in the
> next release.

Thanks!

>> to do. With that small change, json marshals both pointers and values
>> correctly. (I haven't tested unmarshalling yet, but I assume it has
>> the same problem.)
>
> No, unmarshalling cannot change in that regard, otherwise we'd be
> unable to set the id field to the unmarshalled value.

I realized that after I sent the email, but hoped you'd figure it out. ;)

- Evan

Reply all
Reply to author
Forward
0 new messages