1

I have a collection that contains BsonJavascript object.

{ 
    "Name" : "HourlyMP", 
    "MapFunction" : function(){
        var _id = this.srcip + " - " + this.hour
        var valueData = {
            ip: this.srcip,
            session: 1
        }
        emit(_id, valueData);
    } 
}

As you see the value of "MapFunction" field is BsonJavascript. I can Export and Import this data successfully. But when I Deserialize exported json into BsonDocument i get this error:

JSON reader was expecting a value but found 'function'

By the way i am using official C# 2.2 driver and my deserialize code is below:

BsonSerializer.Deserialize<BsonDocument>(myjsonstring)

Edit

I defined function as string then converted it to BsonJavascriptFunction inside my code. This solved my problem. Thanks for reply

Alisettar Huseynli
  • 944
  • 1
  • 11
  • 24

1 Answers1

3

According to the documentation, BsonSerializer.Deserialize<TNominalType>(String) deserializes a JSON string.

Functions aren't valid in JSON.

cbr
  • 12,563
  • 3
  • 38
  • 63
  • https://stackoverflow.com/questions/54201705/mongo-c-sharp-json-reader-was-expecting-a-value-but-found-replsetgetstatus – eran otzap Jan 15 '19 at 15:17