Delete Counter


  • Use the countersFor.delete method to remove a specific Counter from a document.

  • All the document's Counters are deleted when the document itself is deleted.

  • For all other countersFor methods see this Overview.

  • In this page:


delete usage

Flow:

  • Open a session.
  • Create an instance of countersFor.
  • Call countersFor.delete.
  • Call session.saveChanges for the changes to take effect.

Note:

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

Example

// Open a session
const session = documentStore.openSession();
       
// Pass a document ID to the countersFor constructor 
const documentCounters = session.countersFor("products/1-A");

// Delete the "ProductLikes" Counter
documentCounters.delete("ProductLikes");

// The 'Delete' is executed upon calling saveChanges
await session.saveChanges();

Syntax

delete(counter);
Parameter Type Description
counter string Counter's name