Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用聚合<&燃气轮机;函数及其与MongoCollection中的.Aggregate()的不同形式_C#_Mongodb_Aggregation Framework - Fatal编程技术网

C# 使用聚合<&燃气轮机;函数及其与MongoCollection中的.Aggregate()的不同形式

C# 使用聚合<&燃气轮机;函数及其与MongoCollection中的.Aggregate()的不同形式,c#,mongodb,aggregation-framework,C#,Mongodb,Aggregation Framework,我对蒙哥人的世界还很陌生。我试图使用管道方法在c#中执行聚合函数。 使用的MongoDB版本:3.2。 C#驱动程序版本:2.2.4,适用于mongoC#和mongoDB驱动程序 这是密码 MongoClient client = new MongoClient("mongodb://localhost:27017"); IMongoDatabase database = client.GetDatabase("Interaction"); IMongoCollection<Colle

我对蒙哥人的世界还很陌生。我试图使用管道方法在c#中执行聚合函数。 使用的MongoDB版本:3.2。 C#驱动程序版本:2.2.4,适用于mongoC#和mongoDB驱动程序

这是密码

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);
MongoClient=新的MongoClient(“mongodb://localhost:27017");
IMongoDatabase=client.GetDatabase(“交互”);
IMongoCollection=database.GetCollection(“交互”);
//收集结果;
var unwind=新的B单据
{
{
“$REWIND”,
新的B文件
{
{“路径”,“$Pages”}
}
}
};
var group1=新的BsonDocument
{
{
“$group”,
新的B文件
{
{
“_id”,新的B文件
{
{“UrlPath”,“$Pages.Url.Path”},
{“InteractionId”,“$\u id”}
}
},
{
“计数”,新的B记录文件
{
{“$sum”,1}
}
}
}
}
};
var group2=新的BsonDocument
{
{
“$group”,
新的B文件
{
{
“_id”,新的B文件
{
{“UrlPath”,“$\u id.UrlPath”}
}
},
{
“distinctCount”,新的BsonDocument
{
{“$sum”,1}
}
}
}
}
};
var sort=新的BsonDocument
{
{
“$sort”,
新的B文件
{
{“distinctCount”,“-1”}
}
}
};
AggregateArgs管道=新的AggregateArgs();//=新[]{展开,组1,组2,排序};
pipeline.pipeline=new[]{unwind,group1,group2,sort};
##错误##
var result=collection.Aggregate(管道);
交互类只是getter和setter类,代码如下:

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;}                
        }
}
公共静态类集合结构
{
[BsonIgnoreExtraElements]
公共课堂互动
{
公共字符串id{get;set;}
公共字符串contactId{get;set;}
公共字符串channelId{get;set;}
公共字符串语言{get;set;}
公共字符串siteName{get;set;}
公共int值{get;set;}
public int visitPageCount{get;set;}
公共列表页{get;set;}
}
公共类页面
{
公共字符串url{get;set;}
public int visitPageIndex{get;set;}
}
}
所以有两个快速问题:

  • 如何在上述场景中准确地使用聚合函数。如果我做错了什么,请指导我

  • MongoCollection和IMongoCollections这两个独立的集合是什么?何时使用


  • 请帮我做这件事。提前谢谢

    你确定那里应该有
    吗?我找不到任何说明它的文件


    另外,
    通常用于引用类的“模板”,请参见
    列表
    ,我以前从未见过它被用作空的

    您确定那里应该有
    吗?我找不到任何说明它的文件


    另外,
    通常是为类引用“模板”,请参见
    列表
    ,我以前从未见过它被空使用过

    有人能帮助这个新手吗?(浏览相关链接后,我想。聚合()在最新的Mongo版本中,函数可能已被弃用,我使用的是3.2。此外,很多帮助无法联机添加您的c#类,提供驱动程序版本库以供答复。更新了我的问题。如果您需要更多信息@profesor79请检查驱动程序版本3.2调用mogo版本有人请帮助此新手:(在浏览了相关链接后,我认为.Aggregate()函数在最新的Mongo版本中可能已被弃用,我使用的是3.2。此外,很多帮助无法在线添加您的c#类,提供驱动程序版本库以供答复。更新了我的问题。如果您需要更多信息,请联系我@Profesor79请检查驱动程序版本3.2对mogo版本的调用我不是说保持空。我刚刚在上面写道intellisense在VS中向我展示了什么,我不知道如何使用它。你很可能想跳过。对不起,我没有理解你在这里提出的建议。你能解释一下吗?行
    var result=collection.Aggregate(pipeline);
    抛出了什么错误?我怀疑使用行
    var result=collection.Aggregate(管道);
    因为我以前从未见过您使用的版本(我怀疑它可能是无效语法(目前正在电话中,所以我无法测试))。我不是说保持空白。我只是在上面写了intellisense在VS中向我展示的内容,我不知道如何使用它。您很可能想跳过。对不起,我没有理解您在这里提出的建议。您能解释一下吗?行
    var result=collection.Aggregate(pipeline)是哪种错误吗
    抛出?我怀疑使用行
    var result=collection.Aggregate(pipeline);
    因为我以前从未见过您使用的版本(我怀疑它可能是无效语法(目前正在电话中,所以无法测试))。