MongoDB map使用存储的js函数减少c#

时间:2013-02-06 13:27:42

标签: c# mongodb

我使用db.system.js.save命令

保存了我的地图并减少了功能

我想用map reduce调用c#这个函数

MongoClient client = new MongoClient();
        MongoServer server = client.GetServer();
        MongoDatabase test = server.GetDatabase("test");
        MongoCredentials credentials = new MongoCredentials("username", "password");
        var databaseSettings = server.CreateDatabaseSettings("test");
        var database = server.GetDatabase(databaseSettings);

        BsonValue bv = test.Eval("GetSum(3,10)" );

可能吗?

1 个答案:

答案 0 :(得分:2)

回答是;

MongoClient client = new MongoClient();
    MongoServer server = client.GetServer();
    MongoDatabase test = server.GetDatabase("test");
    MongoCredentials credentials = new MongoCredentials("username", "password");
    var databaseSettings = server.CreateDatabaseSettings("test");
    var database = server.GetDatabase(databaseSettings);

    BsonValue bv = test.Eval("GetSum",3,10 ); // return stored js function
BsonValue bv1 = test.Eval(bv .AsBsonJavaScript.Code,3,10); // execute jsfunction