私はMongoの世界ではかなり新しいです。私はパイプラインのアプローチを使用してC#で集約関数を実行しようとしています。 MongoDB使用バージョン:3.2。 C#ドライババージョン:2.2.4両方mongoC#とMongoDBのドライバのがIMongoCollectionでAggregate <>関数を使用する方法とMongoCollectionの.Aggregate()との違いについて
C#はここ
MongoClient client = new MongoClient("mongodb://localhost:27017");
IMongoDatabase database = client.GetDatabase("Interaction");
IMongoCollection<CollectionStructure.Interactions> collection = database.GetCollection <CollectionStructure.Interactions>("Interactions");
//IMongoCollection<CollectionStructure.Interactions> result;
var unwind = new BsonDocument
{
{
"$unwind",
new BsonDocument
{
{"path", "$Pages" }
}
}
};
var group1 = new BsonDocument
{
{
"$group",
new BsonDocument
{
{
"_id", new BsonDocument
{
{"UrlPath", "$Pages.Url.Path"},
{"InteractionId", "$_id"}
}
},
{
"count", new BsonDocument
{
{"$sum", 1}
}
}
}
}
};
var group2 = new BsonDocument
{
{
"$group",
new BsonDocument
{
{
"_id", new BsonDocument
{
{"UrlPath", "$_id.UrlPath"}
}
},
{
"distinctCount", new BsonDocument
{
{"$sum", 1}
}
}
}
}
};
var sort = new BsonDocument
{
{
"$sort",
new BsonDocument
{
{"distinctCount", "-1" }
}
}
};
AggregateArgs pipeline = new AggregateArgs(); //= new[] {unwind,group1,group2,sort};
pipeline.Pipeline = new[] { unwind, group1, group2, sort };
##error##
var result = collection.Aggregate<>(pipeline);
インタラクションクラスは単にゲッタリングされたコードとセッタークラスの、コードは以下の通りである:
public static class CollectionStructure
{
[BsonIgnoreExtraElements]
public class Interactions
{
public string id { get; set; }
public string contactId{ get; set; }
public string channelId { get; set; }
public string language { get; set; }
public string siteName { get; set; }
public int value { get; set; }
public int visitPageCount { get; set; }
public List<Pages> Pages{get; set;}
}
public class Pages
{
public string url {get; set;}
public int visitPageIndex {get; set;}
}
}
だから、2簡単な質問:
Aggreを使用する方法を正確に上記のシナリオでゲート機能。私が何か悪いことをしているなら、私を案内してください。
MongoCollectionとIMongoCollectionsの2つの別個のコレクションとは何ですか?
私を助けてください。事前にありがとう
誰かが私は.Aggregateを考える関連リンクを閲覧した後、この初心者くさい:( – user5510044
を助けてください()関数はおそらく、最新のMongoバージョンでは廃止されました。私は3.2を使用しています。また、多くのヘルプはオンラインで利用できません。 – user5510044
あなたのC#クラスを追加し、ドライババージョン – profesor79