code: function(value, space) {
      /*
        ObjectIds are serialized as @@id
        DBRefs are serialized as @@collection@id or @@collection@@id, depending on whether id is an objectid
        string values starting @ @ are prepended with ::
      */
      return JSON.stringify(value, function(k,v) {
        if (v && typeof v === 'object') {
          //we have to do it like this to avoid toString being call internally
          var copy = new v.constructor();
          for (var prop in v) {
            if (!v.hasOwnProperty(prop)) continue;
            var val = v[prop]
            if (val instanceof ObjectID) {
                val = "@@" + val;
            } else if (val instanceof DBRef) {
              if (val.oid instanceof ObjectID)
                val = '@@' + val.namespace + '@@' + val.oid;
              else
                val = '@@' + val.namespace + '@' + val.oid;
            } else {
              if (typeof val == 'string' && (val.slice(0,2) == '@@')) {
               val = '::' + val;
              }
            }
            copy[prop] = val;
          }
          return copy;
        }
        return v;
      }, space);
    }
docs: XXX escape keys with $ or . with U+FF04 and U+FF0E respectively? http://docs.mongodb.org/manual/faq/developers/#how-does-mongodb-address-sql-or-query-injection