public static void WriteDocument(this BlittableJsonTextWriter writer, JsonOperationContext context, Document document, bool metadataOnly)
        {
            if (document == null)
            {
                writer.WriteNull();
                return;
            }

            if (document == Document.ExplicitNull)
            {
                writer.WriteNull();
                return;
            }

            using (document.Data)
            {
                if (metadataOnly == false)
                {
                    writer.WriteDocumentInternal(context, document);
                }
                else
                {
                    writer.WriteDocumentMetadata(context, document);
                }
            }
        }
        public static void WriteDocument(this BlittableJsonTextWriter writer, JsonOperationContext context, Document document, bool metadataOnly, Func <LazyStringValue, bool> filterMetadataProperty = null)
        {
            if (document == null)
            {
                writer.WriteNull();
                return;
            }

            if (document == Document.ExplicitNull)
            {
                writer.WriteNull();
                return;
            }

            // Explicitly not disposing it, a single document can be
            // used multiple times in a single query, for example, due to projections
            // so we will let the context handle it, rather than handle it directly ourselves
            //using (document.Data)
            {
                if (metadataOnly == false)
                {
                    writer.WriteDocumentInternal(context, document, filterMetadataProperty);
                }
                else
                {
                    writer.WriteDocumentMetadata(context, document, filterMetadataProperty);
                }
            }
        }