see on GitHub

Deleting a Counter

delete Syntax

void delete(String counterName);
Parameter Type Description
counterName String Counter's name

delete Usage

  • Flow:

    • Open a session
    • Create an instance of countersFor.
      • Either pass countersFor an explicit document ID, -or-
      • Pass it an entity tracked by the session, e.g. a document object returned from session.query or from session.load.
    • Execute countersFor.delete
    • Execute session.saveChanges for the changes to take effect
  • Note:

    • A Counter you deleted will be removed only after the execution of saveChanges().
    • Deleting a document deletes its Counters as well.
    • delete will not generate an error if the Counter doesn't exist.

Code Sample

// 1. Open a session
try (IDocumentSession session = docStore.openSession()) {
    // 2. pass CountersFor's constructor a document ID
    ISessionDocumentCounters documentCounters = session.countersFor("products/1-C");

    // 3. Delete the "productLikes" Counter

    // 4. Save changes to the session