How to create a timerseries collection (C# driver)

How can I create a timeseries collection in c# client?

After inspecting resul in MongoDb Compass this code does not seem to actually create a timeseries collection but only a simple collection:

await eveDb.CreateCollectionAsync(
“datapoints”,
new CreateCollectionOptions { TimeSeriesOptions = new TimeSeriesOptions(“timestamp”) }).ConfigureAwait(false);

Moreover I fail to insert data when I create a time series in MongoDb Compass beforehand:
ongoDB.Driver.MongoBulkWriteException`1[InforsHT.Genesis.Core.Domain.Experiments.Entities.DataPoint] : A bulk write operation resulted in one or more errors. WriteErrors: [ { Category : “Uncategorized”, Code : 2, Message : “‘timestamp’ must be present and contain a valid BSON UTC datetime value” } ].

My C# class contains an element:
public BsonDateTime Timestamp { get; set; }

so I don’t get the problem…

just double checked - it is not a time series collection when creating using c# driver:
{{ “name” : “datapoints”, “type” : “collection”, “options” : { }, “info” : { “readOnly” : false, “uuid” : CSUUID(“3cfb7158-9a28-4245-a45d-f37f7f34f133”) }, “idIndex” : { “v” : 2, “key” : { “_id” : 1 }, “name” : “id” } }}
apparently C# driver does cannot create timeseries? at least there is no documentation at all.
term “timeseries” does not even appear in documentation.

This is what I do, and it works.

        if(!CollectionExists("datapoints"))
        _database.CreateCollection("datapoints",
            new CreateCollectionOptions { TimeSeriesOptions = new TimeSeriesOptions("timestamp") });
        _TrendReadingsCollection2 = _database.GetCollection<ExperimentTrendReadings>("datapoints");
1 Like

Thank you for your comment. I’ve tried it and I like it.

You could add an example of inserting and another of obtaining time series.

Thank you very much!!