Repository navigation
BSON Serializer
atheken edited this page Aug 13, 2010
·
28 revisions
MongoSharp’s BSON serializer is very powerful, but you must be careful not to abuse it.
- All readable properties may be:
- int
- bool
- double (floats will be stored as doubles in the db)
- datetime
- string
- byte[]
- BSONOID (this is the default "_id" value that’s generated if you don’t specify something different)
- Regex
- Guid
- IEnumerable&lgt;T>
- T ("where T:class, new()" and follows this rule. )
- A few other types should be supported soon.
- Cyclic graphs are not checked and attempting to serialize them will crash your app, maybe someday this will change, but not this day.
- All public instance properties of the type must be writeable
- All of the types above are supported with three important caveats:
- value-types must use their correspondant Nullable type (i.e. the class must define "int?" properties, rather than "int" properties)
- IEnumerable<T> is always deserialized as List<T>, therefore, your IEnumerable properties must be assignable from List<T>
- Remember how floats are stored as doubles well they are deserialized to "double?"
A general rule in MongoDB is that no document be larger than 4MB, you must take care to adhere to this rule, although a future version of MongoSharp will produce exceptions if you attempt to use documents larger than this size.