执行mongodb查询db.collection.runCommand("text",{"

本文关键字:quot text 查询 mongodb db collection runCommand 执行 | 更新日期: 2023-09-27 18:17:23

我需要添加全文搜索选项在我的网站,数据库mongodb,蒙戈查询:

db.collection.runCommand("text",{"search":"search text"})

给出结果,但如何使用c#执行它?

执行mongodb查询db.collection.runCommand("text",{"

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

来源:Mongo

我在MongoDb中找不到CommandDocument。驱动2.4.4但是JsonCommand工作

var ru = db.RunCommand<BsonDocument>(new MongoDB.Driver.JsonCommand<BsonDocument>("{getLastRequestStatistics: 1}"));

我想你在找这个:

var commandResult = collection.RunCommand(aggregationCommand);
var response = commandResult.Response;
foreach (BsonDocument result in response["results"].AsBsonArray)
{
    // process result
}

很好的例子,但与聚合可以在这里找到:https://groups.google.com/forum/?fromgroups#!主题/mongodb-user/8 dm1lnhh9-q

我比较通用的runCommand的shell到c#的转换规则是这样的:

db.runCommand( <command's json> )

var res = database.RunCommand<BsonDocument>(CommandDocument.Parse("<command's json text>"));