私のサイト、mongodb のデータベース、Mongo Query に全文検索オプションを追加する必要があります。
db.collection.runCommand("text",{"search":"search text"})
結果が得られますが、C# を使用して実行するにはどうすればよいですか?
_collection.Insert(new BsonDocument("x", "The quick brown fox"));
var textSearchCommand = new CommandDocument
{
{ "text", _collection.Name },
{ "search", "fox" }
};
var commandResult = _database.RunCommand(textSearchCommand);
var response = commandResult.Response;
Assert.AreEqual(1, response["stats"]["nfound"].ToInt32());
Assert.AreEqual("The quick brown fox", response["results"][0]["obj"]["x"].AsString);
出典:モンゴ
私はあなたがこれを探していると思います:
var commandResult = collection.RunCommand(aggregationCommand);
var response = commandResult.Response;
foreach (BsonDocument result in response["results"].AsBsonArray)
{
// process result
}
良い例ですが、集計はここにあります: https://groups.google.com/forum/?fromgroups#!topic/mongodb-user/8dM1LnHh9-Q
私のかなり一般的な runCommand のシェルから C# への変換規則は次のようになります。
db.runCommand( <command's json> )
に対応
var res = database.RunCommand<BsonDocument>(CommandDocument.Parse("<command's json text>"));