[ANN] mgo r2013.04.11

Skip to first unread message

Gustavo Niemeyer

Apr 11, 2013, 2:28:06 AM4/11/13
to golan...@googlegroups.com, mongod...@googlegroups.com, mgo-...@googlegroups.com
Quickly following the earlier release of the mgo (http://labix.org/mgo)
MongoDB driver for Go, there's r2013.04.11 leaving the oven just now.

This release brings both a nice improvement for the marshaling of structs,
and a relevant bug fix. The changes are:

- The mgo/bson package (and consequently, mgo itself) now supports the
",inline" tag option on map fields as well. This feature enables the
use of type-rich structs even in situations where the document content
is only partially known. As a simplistic example, a struct such as

type Person struct {
Name string
Phone string
Extra map[string]interface{} `bson:",inline"`

means that the "name" and "phone" document attributes would be
unmarshalled into the Name and Phone fields as usual, but other
unknown attributes that the document presents, if any, would be
preserved in the inlined map.

Marshaling a value of such a struct has the same properties, with
the map contents being marshalled next to the other fields.

More details about supported options and their meaning at:


- A bug was fixed on the cluster synchronization mechanism in cases
where the primary server suffers a very short fallout and quickly
reestablishes its functionality as a secondary. In those situations,
mgo might still consider it as a primary and attempt to deliver
primary-specific commands. When the bug happened, no serious
consequences would arise other than "not master" error messages.
The bug was properly fixed and tested against to prevent regressions.

The discovery was made thanks to a new service being introduced by
MongoLabs, to be announced in the upcoming days.

- This release also brings down the replica set cluster synchronization
delay from 3 minutes to 30 seconds. This delay was and still is the
maximum delay, and there are events that may trigger such a
synchronization to happen sooner.

gustavo @ http://niemeyer.net

adnaan badr

May 13, 2013, 3:15:27 PM5/13/13
to golan...@googlegroups.com, mongod...@googlegroups.com, mgo-...@googlegroups.com, piyush...@gmail.com
Try  bson.Unmarshal(b, o) instead of  bson.Unmarshal(b, &o)

On Monday, 13 May 2013 19:46:36 UTC+5:30, piyush...@gmail.com wrote:
I am experiencing some odd behaviour with `inline`
When I return the output struct the thing works like a charm, but fails when I pass a reference to the destination object.
Am i missing something here ?


package main

import (

type Base struct {
    Id string `bson:"_id" json:"_id"`
    ValueOn int `bson:"value_on" json:"value_on"`

type User struct {
    Base ",inline"
    Firstname string `bson:"first_name" json:"first_name"`

func BsonWithInterface(d interface{}, o interface{}) {
    b, _ := bson.Marshal(d)
    bson.Unmarshal(b, &o)

func BsonWithUser(d interface{}, o *User) {
    b, _ := bson.Marshal(d)
    bson.Unmarshal(b, &o)

func BsonWithReturn(d interface{}) User {
    var tmp User
    b, _ := bson.Marshal(d)
    bson.Unmarshal(b, &tmp)
    return tmp

func main() {
    var bson_tmp User
    var strict_tmp User

    x := User{Base{"1234", 5}, "Jaideep"}
    BsonWithInterface(x, &bson_tmp)
    log.Println("func (interface, interface):", bson_tmp.ValueOn, bson_tmp.Id)

    BsonWithUser(x, &strict_tmp)
    log.Println("func (interface, user):", bson_tmp.ValueOn, bson_tmp.Id)

    y := BsonWithReturn(x)
    log.Println("func (interface) User:", y.ValueOn, y.Id)

Output is 
2013/05/13 19:44:17 func (interface, interface): 0 
2013/05/13 19:44:17 func (interface, user): 0 
2013/05/13 19:44:17 func (interface) User: 5 1234

Instead of 
2013/05/13 19:44:17 func (interface, interface): 5 1234
2013/05/13 19:44:17 func (interface, user): 5 1234
2013/05/13 19:44:17 func (interface) User: 5 1234

Gustavo Niemeyer

May 13, 2013, 4:37:27 PM5/13/13
to mgo-...@googlegroups.com

And don't ever throw away errors like that! The package would raise the issue.

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.
Reply all
Reply to author
0 new messages