sql >> Base de Datos >  >> NoSQL >> MongoDB

Almacenamiento de estructuras anidadas con mgo

Creo que usar inline etiqueta de campo es la mejor opción para usted. La documentación de mgo/v2/bson dice:

inline     Inline the field, which must be a struct or a map,
           causing all of its fields or keys to be processed as if
           they were part of the outer struct. For maps, keys must
           not conflict with the bson keys of other struct fields.

Su estructura debe definirse de la siguiente manera:

type Cube struct {
    Square `bson:",inline"`
    Depth  int
}

Editar

inline también existe en mgo/v1/bson en caso de que estés usando ese.