0

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?

2
  • did you get any progress on that? Commented Mar 2, 2016 at 22:09
  • I programmed my JavaScript in a different way that involves returning an array of documents belonging to a MongoDB collection, and then I used the BsonSerializer to Deserialize the JSON (Please click on the link here ): stackoverflow.com/questions/35554495/… Commented Mar 25, 2016 at 15:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.