Session: 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.

  • This does not load the document from the server or cause the session to track it.

  • In this page:


Syntax

bool Exists(string id);
Task<bool> ExistsAsync(string documentId, CancellationToken token = default);
Parameter Type Description
id string The ID of the document you want to check the database for
Return Value Description
bool Indicates whether a document with the specified ID exists in the database

Example

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

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

if (exists)
{
    //do something
}