Skip to main content

Commands: Documents: How to get document metadata only?

Head is used to retrieve document metadata from a database.

Syntax

public GetDocumentsCommand(string id, string[] includes, bool metadataOnly)
Parameters
keystringkey of a document to get metadata for
Return Value
JsonDocumentMetadataMetadata information for document with given key.

Example

var command = new GetDocumentsCommand("orders/1-A", null, metadataOnly: true);
session.Advanced.RequestExecutor.Execute(command, session.Advanced.Context);
var result = (BlittableJsonReaderObject)command.Result.Results[0];
var documentMetadata = (BlittableJsonReaderObject)result["@metadata"];

// Print out all the metadata properties.
foreach (var propertyName in documentMetadata.GetPropertyNames())
{
documentMetadata.TryGet<object>(propertyName, out var metaPropValue);
Console.WriteLine("{0} = {1}", propertyName, metaPropValue);
}