Deleting a Counter
-
All the Counters for a document are deleted when the document is deleted.
-
You can also use the CountersFor.
Delete
method to remove a specific Counter from a document. -
In this page:
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.
- Either pass
- 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.
- A Counter you deleted will be removed only after the execution of
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();
}