0
我寫了一個自動完成腳本,其工作速度非常快,但是當我將它部署到IIS時,只要輸入一個新的字母就會花費28s。我究竟做錯了什麼?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();
}