0

All:

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

Using the MongoDB C# Driver Version 1.7.0.4714 API, I can construct queries using IMongoQuery and the Query object,

However, I find it difficult to implement queries using the MongoDB C# Driver Version 1.7.0.4714 API when the query involves a lot of "quasi-joins" between MongoDB Collections.

Also, I believe it slows performance if you bring in large amount of data from MongoDB world into C# world as POCO objects in a list.

So, I was thinking if it would be good to adopt the implementation practice of using C# to invoke stored JavaScript in MongoDB.

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

            sysJs.Remove(Query.EQ("_id", "getUsers"));

            var code =     File.ReadAllText(HttpContext.Current.Server.MapPath("~/Hos/quasiStoredProcedures    JS/getUsers.js"));


            var codeDocument = new BsonDocument("value", new        BsonJavaScript(code));

            codeDocument.Add(new BsonElement("_id", "getUsers"));

            sysJs.Insert(codeDocument);

 BsonValue getUsers = DBConnection.database.Eval("getUsers");


            BsonValue bv3 =      DBConnection.database.Eval(getUsers.AsBsonJavaScript.Code, null
                                                                                                ,
loggedInUser.CompanyID
                                                                                                      ,
 searchTermArg 
                                                                                                      ,
ApplicationConstants.DriverRole
                                                                                                       ,
startRowOfInterest
                                                                                                        ,
displayedRowsQuantity
                                                                                                     ,
sortColumn
                                                                                                      ,
isAscending);


            IEnumerable<Users> usersOfInterestList =         bv3.AsBsonArray.AsQueryable();  

Is it better to start using C# invocation of stored javaScript in MongoDB as opposed to used MongoDB C# Driver Version 1.7.0.4714 API Query API?

2
  • Except... if you have authentication turned on, you have to have a role with "AnyAction on AnyResource" permission assigned to your user in order to execute "eval". This is a huge security risk as the default db user for your app would have global access to all functions on all databases and resources. see docs.mongodb.org/manual/reference/command/eval/#access-control Commented May 2, 2016 at 4:08
  • Update: Apparently "eval" is being dropped in a future version - although replacement functions are not yet available. see: jira.mongodb.org/browse/SERVER-17453 Commented May 2, 2016 at 4:09

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.