So, I thought I'd give LiteDB a try, but I'm struggling a bit!
Trying to write log data to it. So, what I have so far (simplified)
A class (the data strinture)
private class PerBarData
{
public DateTime ts { get; set; }
public double o { get; set; }
public double h { get; set; }
public double l { get; set; }
public double c { get; set; }
public double v { get; set; }
public Dictionary<int, double> r { get; set; }
}
And I'm writing data to LiteDB like so
// Get a collection (or create, if doesn't exist)
var col = db.GetCollection<PerBarData>("PerBarData");
Dictionary<int, double> dict = new Dictionary<int, double>();
for (int i=1; i<maxIndexes; i++)
{
dict.Add(i,plotBIAS[i]);
}
// Create your new customer instance
var pbd = new PerBarData
{
ts = Time[1],
o = Open[1],
h = High[1],
l = Low[1],
c = Close[1],
v = Volume[1],
r = dict
};
// Insert new customer document (Id will be auto-incremented)
col.Insert(pbd);
Which seems to work, as records are in deed being added. I can see that in the LiteDB studio. I can only see what presumably is serialised text though. Objects like this
/* 1 */
{
"_id": {"$oid": "6009b32dfb2026288486321a"}
}
/* 2 */
{
"_id": {"$oid": "6009b39dfb2026288486321b"}
}
So - Presumably, that bit I go right, so far. So, to retrieve some data. All I want, is data between 2 dates, or at least, exceeding one date. So, I try this
DateTime startDate = Time[CurrentBar-1];
DateTime endDate = Time[0];
var col = db.GetCollection<PerBarData>("PerBarData");
// Use LINQ to query documents (filter, sort, transform)
var results = col.Find(Query.GTE("ts", startDate));
foreach(var pbd in results)
{
PPrint(pbd.ts.ToString());
}
But, it typically just hangs there. Certainly, no dates are printed. I was originally trying Query.Between and the 2 dates. Same.
Can anyone push me in the right direction please? I'd really like to give this a proper try.
Thanks.