Skip to main content

Deleting a Counter

Delete Syntax

void Delete(string counterName);
ParameterTypeDescription
counterNamestringCounter'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
documentCounters.Delete("ProductLikes");

// 4. Save changes to the session
session.SaveChanges();
}