Skip to content

Commit

Permalink
fixed aggregate, filter and sort
Browse files Browse the repository at this point in the history
  • Loading branch information
merl111 committed Aug 11, 2020
1 parent d409e93 commit 0c3709b
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions EventTracker/EventTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,18 @@ private JObject HandleGetBlockIds(JArray _params)

var filter = builder.And(filters);
var sort = Builders<BsonDocument>.Sort.Ascending("block_index");
//var blockIds = collection.Distinct<ulong>("block_index", filter);//.ToDictionary(x => x.).OrderBy(x => x);
var blockIds = new Dictionary<ulong,string>();

collection.Aggregate().Group(new BsonDocument("_id", new BsonDocument {
{"block_index", "$block_index"},
{"block_hash", "$block_hash"}
})).ToList().ForEach(
doc => {
var data = doc["_id"];
blockIds.Add((ulong)data["block_index"].AsInt32, data["block_hash"].AsString);
});
collection.Aggregate().Match(filter).Group(new BsonDocument("_id",
new BsonDocument { {"block_index", "$block_index"}, {"block_hash", "$block_hash"} }
)
)
.ToList().ForEach( doc => {
var data = doc["_id"];
blockIds.Add((ulong)data["block_index"].AsInt32, data["block_hash"].AsString);
});

var objects = new JArray();
foreach (var entry in blockIds)
foreach (var entry in blockIds.OrderBy(x => x.Key))
{
JObject item = new JObject();
item["block_index"] = entry.Key;
Expand Down

0 comments on commit 0c3709b

Please sign in to comment.