code: public static Document readDocument(
              BsonReader reader,
              DecoderContext decoderContext,
              Map<String, Decoder<?>> fieldDecoders) {
  
          Document document = new Document();
          reader.readStartDocument();
          while (reader.readBsonType() != END_OF_DOCUMENT) {
              String fieldName = reader.readName();
              if (fieldDecoders.containsKey(fieldName)) {
                  document.put(
                          fieldName,
                          fieldDecoders
                                  .get(fieldName)
                                  .decode(reader, decoderContext)
                  );
              }
              else {
                  throw new BsonInvalidOperationException(format(
                          "The field %s is not expected here", fieldName
                  ));
              }
          }
          reader.readEndDocument();
          return document;
      }
docs: Document codecs