2016-08-07 1 views
0

良い一日のすべての機能を取得する:どのように私ははMongoDBのデータベース・オブジェクトから、関数の定義にアクセスすることができましたか?のMongoDB + C#の - 、</p> <p>質問あるデータベース

 const string connectionString = "mongodb://localhost"; 

     // Create a MongoClient object by using the connection string 
     var client = new MongoClient(connectionString); 

     //Use the MongoClient to access the server 
     MongoServer server = client.GetServer(); 

     // Use the server to access the 'local' database 
     var database = server.GetDatabase("local"); 

     //What next? 
     //................................................. 
+1

関数の定義はどういう意味ですか?あなたがMongoDbに持っている関数のように?または、コンソールからのヘルプログのように? –

+0

答えをありがとう。私はカスタムのユーザー定義関数を意味します。 – user306080

答えて

1

機能コード自体の値を取得するのようにそれらを得る意味場合、それらはデータベースのsystem.jsコレクションに格納されています。他のコレクションと同様に、それらすべてを取得します。

db.system.js.find({}); 

C#の場合:

var database = server.GetDatabase("databaseName"); 

var collection = database.GetCollection<BsonDocument>("system.js"); 
var filter = new BsonDocument(); 
var count = 0; 
using (var cursor = await collection.FindAsync(filter)) 
{ 
    while (await cursor.MoveNextAsync()) 
    { 
     var batch = cursor.Current; 
     foreach (var document in batch) 
     { 
      // process document 
      count++; 
     } 
    } 
} 

あなたはsystem.jsオブジェクト{ _id: "two", value: "function(x, y) { return x + y; }" }が含まれている場合は、コード内でそれらを呼び出すことを意味する場合は、次のように、あなたが実行して関数を呼び出すことができますループの中で:

database.Eval(document.getValue("value")).ToString(); 
関連する問題