0

我用 db.system.js.save 命令保存了我的 map 和 reduce 函数,

我想在 c# 中调用这个函数与 map reduce 相同的

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)" );

有可能吗?

4

1 回答 1

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
于 2013-05-07T08:12:41.883 回答