C# world has problems retrieving valid data from javaScript function that is gets data from MongoDB

此生再无相见时 提交于 2019-12-12 03:31:17

问题


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?

来源:https://stackoverflow.com/questions/35456071/c-sharp-world-has-problems-retrieving-valid-data-from-javascript-function-that-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!