This project has moved. For the latest updates, please go here.

Why are $id and $ref written as strings?

Jul 9, 2010 at 10:39 AM

When using JsonSerializerSettings.PreserveReferencesHandling, I noticed that the reference Id's are written as text strings.  Wouldn't it be more efficient to write them as integers?

Except in the case of less than a thousand objects, it seems the BSON integer representation would always use less bytes than a string.  The resulting file would probably gzip better as well.

Jul 9, 2010 at 1:58 PM

IReferenceResolver allows references to be customized and a string offers much more flexibility than an integer.