Skip to main content

Session: Delete Time Series

Delete a range of time series entries using TimeSeriesFor.Delete.

TimeSeriesFor.Delete

TimeSeriesFor.Delete is used for the removal of time series and time series entries.

  • There is no need to explicitly delete a time series; the series is deleted when all its entries are deleted.
  • Attempting to delete nonexistent entries results in a no-op, generating no exception.

Syntax

  • There are two TimeSeriesFor.Delete methods:
    • Delete a single time series entry.
// Delete a single time-series entry
void Delete(DateTime at);
  • Delete a range of time series entries.
// Delete a range of time-series entries
void Delete(DateTime? from = null, DateTime? to = null);
  • Parameters

    ParametersTypeDescription
    atDateTimeTimestamp of the time series entry you want to delete.
    from (optional)DateTime?Delete the range of time series entries starting at this timestamp.
    Default: DateTime.Min
    to (optional)DateTime?Delete the range of time series entries ending at this timestamp.
    Default: DateTime.Max

| from | DateTime | Range Start (optional)
| to | DateTime | Range End (optional)
Default: DateTime.Max

  • Return Value
    No return value.

  • Exceptions

    • DocumentDoesNotExistException is thrown If the document doesn't exist.
    • Attempting to delete nonexistent entries results in a no-op and does not generate an exception.

Usage Flow

  • Open a session.
  • Create an instance of TimeSeriesFor.
  • Call TimeSeriesFor.Delete.
  • Call session.SaveChanges for the action to take effect on the server.

Usage Samples

  • Delete a single entry:
// Delete a single entry
using (var session = store.OpenSession())
{
session.TimeSeriesFor("users/john", "HeartRates")
.Delete(baseline.AddMinutes(1));

session.SaveChanges();
}
  • Delete a range of entries:
// Delete a range of entries from the time series
using (var session = store.OpenSession())
{
session.TimeSeriesFor("users/john", "HeartRates")
.Delete(baseline.AddSeconds(0), baseline.AddSeconds(9));

session.SaveChanges();
}