You are currently browsing legacy 4.1 version of documentation. Click here to switch to the newest 5.1 version.

We can help you with migration to the latest RavenDB

Contact Us Now
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.
    • 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
using (var session = docStore.OpenSession())
    // 2. pass CountersFor's constructor a document ID  
    var documentCounters = session.CountersFor("products/1-C");

    // 3. Delete the "ProductLikes" Counter

    // 4. Save changes to the session