0
非常に高速なオートコンプリートスクリプトを作成しましたが、IISにデプロイすると新しい文字を入力するたびに28秒かかります。私は間違って何をしていますか?私は私の方法は、すべてこのwebmethodが結果を返すのに時間がかかりすぎる
コードのためのAjaxとjQueryを使用してい
は以下の通りです:
[WebMethod]
public static string[] GetCustomers(string prefix)
{
string connectionString = "mongodb://localhost:27017";
MongoClientSettings settings = MongoClientSettings.FromUrl(new MongoUrl(connectionString));
MongoClient mongoClient = new MongoClient(settings);
var _database = mongoClient.GetDatabase("test");
IMongoCollection<BsonDocument> collection = _database.GetCollection<BsonDocument>("mycollection");
var filter = new BsonDocument { { "name", new BsonDocument { { "$regex", prefix }, { "$options", "i" } } } };
var sort = Builders<BsonDocument>.Sort.Descending("mycolumn");
var fields = Builders<BsonDocument>.Projection.Include("name").Include("anothercolumn");
var c = collection.Find(filter).Sort(sort).Project(fields).Limit(10).ToList(); // or toCursor
List<string> customers = new List<string>();
foreach (var document in c)
{
document.Elements.ElementAt(2).Value, document.Elements.ElementAt(1).Value));
}
return customers.ToArray();
}