命令mapreduce失败:错误:BSONElement

时间:2016-04-05 15:00:27

标签: c# mongodb

在MongoDB中运行mapreduce函数时,我有时会收到此错误:

Command mapreduce failed: Error: Error: BSONElement: bad type -16 :\n_funcs7@:1:236\n.

bad type表达式之后的数字每次更改并采用不同的数字。我用谷歌搜索,但没有找到任何答案的错误。

P.S。我正在使用c#驱动程序(MongoDB.Driver 2.2.3)和MapReduceAsync方法来运行mapreduce函数。

修改

这是我的代码:

public static async Task<bool> RunMapReduce(IMongoCollection<BsonDocument> collection, MPFunction mpFunction)
{
    try
    {
        await collection.MapReduceAsync(mpFunction.MapFunction, mpFunction.ReduceFunction, mpFunction.MpOptions);
        return true;
    }
    catch (Exception ex)
    {
        return false;
    }
}

MPFunction是用于保持map和reduce函数以及其他一些mapreduce选项的类。

这是此错误的堆栈跟踪:

MongoDB.Driver.MongoCommandException was caught
  HResult=-2146233088
  Message=Command mapreduce failed: Error: Error: BSONElement: bad type 112 :
_funcs7@:1:236
.
  Source=MongoDB.Driver.Core
  Code=10320
  ErrorMessage=Error: Error: BSONElement: bad type 112 :
_funcs7@:1:236

  StackTrace:
       at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.ProcessReply(ConnectionId connectionId, ReplyMessage`1 reply)
       at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.<ExecuteAsync>d__11.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
       at MongoDB.Driver.Core.Servers.ClusterableServer.ServerChannel.<ExecuteProtocolAsync>d__26`1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
       at MongoDB.Driver.Core.Operations.CommandOperationBase`1.<ExecuteProtocolAsync>d__29.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
       at MongoDB.Driver.Core.Operations.WriteCommandOperation`1.<ExecuteAsync>d__2.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
       at MongoDB.Driver.Core.Operations.MapReduceOutputToCollectionOperation.<ExecuteAsync>d__23.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
       at MongoDB.Driver.OperationExecutor.<ExecuteWriteOperationAsync>d__3`1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
       at MongoDB.Driver.MongoCollectionImpl`1.<ExecuteWriteOperationAsync>d__61`1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
       at MongoDB.Driver.MongoCollectionImpl`1.<MapReduceAsync>d__36`1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
  InnerException:

也许这些细节也很有用:

在mongo shell中运行相同的MapReduce函数时,我没有收到错误。这是我的地图&#34;并且&#34;减少&#34;功能:

注意:我正在使用Perform Incremental Map-Reduce中描述的递增减少逻辑。获取原始数据时,MAP1用于第一次迭代,并生成每小时摘要。 MAP2用于其他迭代,它获得每小时摘要并减少到每日,每月等。错误通常发生在增量(每日,每月等)阶段。

MAP1: function(){

    var id = this.hostname ? this.hostname : '';
    id += this.catdesc ? this.catdesc : '';

    var value = {
        hostname: this.hostname,
        catdesc: this.catdesc,
        sentbyte: this.sentbyte,
        rcvdbyte: this.rcvdbyte,
        session: 1
    };

    emit(id, value);
}

MAP2: function(){     
        emit(this._id, this.value);   
    }

REDUCE: function(key, valueData){

        reducedVal = {
            hostname: valueData[0].hostname,
            catdesc: valueData[0].catdesc,
            sentbyte: 0,
            rcvdbyte: 0,
            session: 0
        }

        for (var i = 0; i < valueData.length; i++) {
            reducedVal.sentbyte += valueData[i].sentbyte;
            reducedVal.rcvdbyte += valueData[i].rcvdbyte;
            reducedVal.session += valueData[i].session;
        }

        return reducedVal;

    }

0 个答案:

没有答案