Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.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# MapReduce在Mongo Shell中工作,而不是在C中#_C#_Mongodb - Fatal编程技术网

C# MapReduce在Mongo Shell中工作,而不是在C中#

C# MapReduce在Mongo Shell中工作,而不是在C中#,c#,mongodb,C#,Mongodb,我正在尝试在应用程序中运行MapReduce查询。我已经创建了相关的JS,并通过Mongo Shell验证了它的有效性: var map = function() { if (this.class_artist != null) for (var i = 0; i < this.class_artist.length; i++) { var key = { artist: this.class_artist[i],

我正在尝试在应用程序中运行MapReduce查询。我已经创建了相关的JS,并通过Mongo Shell验证了它的有效性:

var map = function() {
    if (this.class_artist != null)
    for (var i = 0; i < this.class_artist.length; i++) {
        var key = {
            artist: this.class_artist[i],
            language:  this.language.substring(0,2),
        };
        var value = {
            count: 1
        };
        emit(key, value);
    }
}
var reduce = function(key, value) {
    var sum = 0;
    value.forEach(function(value) {
        sum += value['count'];
    });
    return {count: sum};
}
db.articles.mapReduce(map, reduce, {out: {inline: 1}})
var map=function(){
if(this.class_artist!=null)
for(var i=0;i
我有以下c#翻译:

    var articleCollection = database.GetCollection<Article_Base>("articles");

string map = @"var map = function() {
            if (this.class_artist != null)
            for (var i = 0; i < this.class_artist.length; i++) {
                var key = {
                    artist: this.class_artist[i],
                    language:  this.language.substring(0,2),
                };
                var value = {
                    count: 1
                };
                emit(key, value);
            }
        }";
string reduce = @"var reduce = function(key, value) {
            var sum = 0;
            value.forEach(function(value) {
                sum += value['count'];
            });
            return {count: sum};
        }";
var options = new MapReduceOptionsBuilder();
options.SetOutput(MapReduceOutput.Inline);
var result = articleCollection.MapReduce(map, reduce, options).GetResults();
var articlecolection=database.GetCollection(“articles”);
字符串映射=@“var映射=函数(){
if(this.class_artist!=null)
for(var i=0;i
然而,即使我使用相同的map&reduce函数,c代码也不会返回任何结果

我是mapReduce的新手,尽管阅读了文档,但我不确定如何继续


任何帮助都将不胜感激

您的翻译太直译,只需将函数定义为字符串:

string map = @"function() {" // and the rest of it

然后mapReduce方法需要处理一些事情

尝试删除“var”声明,并将函数定义为字符串。这很有效!如果您将回复从评论改为回复,我将接受:)