Here is information about my development environment:
- MongoDB 3.0.0
- MongoDB driver version C # 1.7.0.4714
- Microsoft Visual Studio Professional 2013
- .NET Framework 4.0
We have code that uses the C # MongoDB Driver API to call a JavaScript file that will query the MongoDB database.
Here is an excerpt from 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 get the returned JavaScript data by placing it in bv1, I saw the following using the Visual Studio Add Watch function:
bv1 {}
Can anyone explain how I can get the correct values ββin the C # world?
CS Lewis
source share