Ich bin ziemlich neu in der Mongo-Welt. Ich versuche, eine Aggregatfunktion in C# mit Pipeline-Ansatz auszuführen. Verwendete MongoDB-Version: 3.2. C# Treiber Version: 2.2.4 für beide mongoC# und mongoDB TreiberVerwenden Aggregate <> Funktion in IMongoCollection und wie es anders ist .Aggregate() in MongoCollection
C# Hier ist der Code
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);
Interaktion Klasse ist einfach Getter und Setter-Klasse, Code ist wie folgt:
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;}
}
}
So 2 kurze Fragen:
Wie genau Aggre zu verwenden Gate-Funktion im obigen Szenario. Bitte führe mich, wenn ich etwas falsch mache.
Was sind diese 2 separate Sammlung MongoCollection und IMongoCollections und wann was zu verwenden.
Bitte helfen Sie mir dabei. Vielen Dank im Voraus
Kann jemand bitte diese newb helfen :( – user5510044
die entsprechenden Links Nach dem Surfen ich denke .Aggregate() Funktion ist wahrscheinlich veraltet in der neuesten Mongo-Version, ich verwende 3.2. Auch viel Hilfe ist nicht online verfügbar – user5510044
fügen Sie Ihre C# -Klasse, Treiberversion zur Verfügung stellen – profesor79