|
| 1 | +// Package mgocompat provides MgoRegistry, a BSON registry compatible with globalsign/mgo's BSON, |
| 2 | +// with some remaining differences. It also provides MgoRegistryRespectNilValues for compatibility |
| 3 | +// with mgo's BSON with RespectNilValues set to true. A registry can be configured on a |
| 4 | +// mongo.Client with the SetRegistry option. See the bsoncodec docs for more details on registries. |
| 5 | +// |
| 6 | +// MgoRegistry supports Getter and Setter equivalents by registering hooks. Note that if a value |
| 7 | +// matches the hook for bsoncodec.Marshaler, bsoncodec.ValueMarshaler, or bsoncodec.Proxy, that |
| 8 | +// hook will take priority over the Getter hook. The same is true for the hooks for |
| 9 | +// bsoncodec.Unmarshaler and bsoncodec.ValueUnmarshaler and the Setter hook. |
| 10 | +// |
| 11 | +// The functional differences between MgoRegistry and globalsign/mgo's BSON library are: |
| 12 | +// |
| 13 | +// 1) MgoRegistry errors instead of silently skipping mismatched types when decoding. |
| 14 | +// |
| 15 | +// 2) MgoRegistry does not have special handling for marshaling array ops ("$in", "$nin", "$all"). |
| 16 | +// |
| 17 | +// The driver uses different types than mgo's bson. The differences are: |
| 18 | +// |
| 19 | +// 1) The driver's bson.RawValue is equivalent to mgo's bson.Raw, but uses Value instead |
| 20 | +// of Data and uses Type, which is a bsontype.Type object that wraps a byte, instead of |
| 21 | +// bson.Raw's Kind, a byte. |
| 22 | +// |
| 23 | +// 3) The driver uses primitive.ObjectID, which is a [12]byte instead of mgo's |
| 24 | +// bson.ObjectId, a string. Due to this, the zero value marshals and unmarshals differently |
| 25 | +// for Extended JSON, with the driver marshaling as `{"ID":"000000000000000000000000"}` and |
| 26 | +// mgo as `{"Id":""}`. The driver will not unmarshal {"ID":""} to a primitive.ObjectID. |
| 27 | +// |
| 28 | +// 4) The driver's primitive.Symbol is equivalent to mgo's bson.Symbol. |
| 29 | +// |
| 30 | +// 5) The driver uses primitive.Timestamp instead of mgo's bson.MongoTimestamp. While |
| 31 | +// MongoTimestamp is an int64, primitive.Timestamp stores the time and counter as two separate |
| 32 | +// uint32 values, T and I respectively. |
| 33 | +// |
| 34 | +// 6) The driver uses primitive.MinKey and primitive.MaxKey, which are struct{}, instead |
| 35 | +// of mgo's bson.MinKey and bson.MaxKey, which are int64. |
| 36 | +// |
| 37 | +// 7) The driver's primitive.Undefined is equivalent to mgo's bson.Undefined. |
| 38 | +// |
| 39 | +// 8) The driver's primitive.Binary is equivalent to mgo's bson.Binary, with variables named Subtype |
| 40 | +// and Data instead of Kind and Data. |
| 41 | +// |
| 42 | +// 9) The driver's primitive.Regex is equivalent to mgo's bson.RegEx. |
| 43 | +// |
| 44 | +// 10) The driver's primitive.JavaScript is equivalent to mgo's bson.JavaScript with no |
| 45 | +// scope and primitive.CodeWithScope is equivalent to mgo's bson.JavaScript with scope. |
| 46 | +// |
| 47 | +// 11) The driver's primitive.DBPointer is equivalent to mgo's bson.DBPointer, with variables |
| 48 | +// named DB and Pointer instead of Namespace and Id. |
| 49 | +// |
| 50 | +// 12) When implementing the Setter interface, mgocompat.ErrSetZero is equivalent to mgo's |
| 51 | +// bson.ErrSetZero. |
| 52 | +// |
| 53 | +package mgocompat |
0 commit comments