Bulk Insert: How to Append Time Series
-
store.BulkInsert
is RavenDB's high-performance data insertion operation.
Using itsTimeSeriesFor
interface'sAppend
method resembles using session.TimeSeriesFor, butsession
liabilities are omitted so a much greater speed is gained. -
You can bulk-insert a single time series at a time.
-
To bulk-insert an additional time series concurrently, open an additional BulkInsertOperation instance.
-
In this page:
Syntax
BulkInsert.TimeSeriesFor
public TimeSeriesBulkInsert TimeSeriesFor(string id, string name)
Parameters | Type | Description |
---|---|---|
id | string | Document ID |
name | string | Time Series Name |
- There are two
TimeSeriesFor.Append
overloads:
// Append a single value
public void Append(DateTime timestamp, double value, string tag = null)
// Append multiple values
public void Append(DateTime timestamp, ICollection<double> values, string tag = null)
Parameters | Type | Description |
---|---|---|
timestamp | DateTime | TS-entry's timestamp |
value | double | A single value |
values | ICollection<double> | Multiple values |
tag | string | TS-entry's tag (optional) |
Usage Flow
- Create a
store.BulkInsert
instance. - Pass the instance's
TimeSeriesFor
-- Document ID
- Time series name
- Call
Append
as many times as you like. Pass it -- The entry's Timestamp
- The entry's Value or Values
- The entry's Tag (optional)
Usage Samples
- In this sample, we append two entries to a time series.
// Use BulkInsert to append 2 time-series entries
using (BulkInsertOperation bulkInsert = store.BulkInsert())
{
using (TimeSeriesBulkInsert timeSeriesBulkInsert = bulkInsert.TimeSeriesFor(documentId, "HeartRates"))
{
timeSeriesBulkInsert.Append(baseline.AddMinutes(2), 61d, "watches/fitbit");
timeSeriesBulkInsert.Append(baseline.AddMinutes(3), 62d, "watches/apple-watch");
}
}
- In this sample, we append a hundred entries to a time series.
using (BulkInsertOperation bulkInsert = store.BulkInsert())
{
using (TimeSeriesBulkInsert timeSeriesBulkInsert =
bulkInsert.TimeSeriesFor("users/john", "HeartRates"))
{
Random rand = new Random();
for (int i = 0; i < 100; i++)
{
double randomValue = rand.Next(60, 91);
timeSeriesBulkInsert.Append(baseTime.AddMinutes(i), randomValue, "watches/fitbit");
}
}
}
- In this sample, we append two sets of values to a time series.
using (BulkInsertOperation bulkInsert = store.BulkInsert())
{
using (TimeSeriesBulkInsert timeSeriesBulkInsert =
bulkInsert.TimeSeriesFor("users/john", "HeartRates"))
{
var exerciseHeartRates = new List<double> { 89d, 82d, 85d };
timeSeriesBulkInsert.Append(baseline.AddMinutes(1), exerciseHeartRates, "watches/fitbit");
var restingHeartRates = new List<double> { 59d, 63d, 61d, 64d, 65d };
timeSeriesBulkInsert.Append(baseline.AddMinutes(2), restingHeartRates, "watches/apple-watch");
}
}