-->

C# world has problems retrieving valid data from j

2019-09-12 07:29发布

问题:

Here is the information about my development environment:

  • MongoDB 3.0.0
  • MongoDB C# Driver Version 1.7.0.4714
  • Microsoft Visual Studio Professional 2013
  • .NET Framework 4.0

We have code that uses C# MongoDB Driver API to invoke a JavaScript file that will query the MongoDB database.

Here is the excerpt of the said C# code:

var sysJs = DBConnection.database.GetCollection("system.js");

sysJs.Remove(Query.EQ("_id", "getArray"));
var code = File.ReadAllText(HttpContext.Current.Server.MapPath("~/folderPathtoJSFile/getArray.js"));

var codeDocument = new BsonDocument("value", new BsonJavaScript(code));
codeDocument.Add(new BsonElement("_id", "getArray"));

sysJs.Insert(codeDocument);

BsonValue bv = DBConnection.database.Eval("getArray");

BsonValue bv1 = DBConnection.database.Eval(bv.AsBsonJavaScript.Code, blahIdArg, BlahStatusArg);

Here is the contents of the getArray.js JavaScript file:

function (blahIdArg, BlahStatusArg) {

    var someJavaScriptObjectMap = {};
    someJavaScriptObjectMap["firstEntry"] = "JohnDoe";
    someJavaScriptObjectMap["secondEntry"] = "JaneDoe";

    return someJavaScriptObjectMap;
} 

When I try to retrieve the returned JavaScript data by placing it in bv1, I saw the following using the Visual Studio Add Watch feature:

bv1 {}

Could someone please explain how I can retrieve the properly values in the C# world?