How to Check if a Document Exists


  • To check whether the database contains a certain document,
    use the method Exists() from the Advanced session operations.

  • Calling 'Exists' does not Load the document entity to the session,
    and the session will not track it.

  • In this page:


Check if document exists

bool exists = session.Advanced.Exists("employees/1-A");

if (exists)
{
    // document 'employees/1-A exists
}
bool exists = await asyncSession.Advanced.ExistsAsync("employees/1-A");

if (exists)
{
    // document 'employees/1-A exists
}

Syntax

bool Exists(string id);
Task<bool> ExistsAsync(string documentId, CancellationToken token = default);
Parameter Type Description
id string The ID of the document to check
Return Value Description
bool true - the document exists in the database.
false - The document does Not exist in the database