C# Mongo Client 2.4.2创建索引

static async Task CreateIndex()
{
    var client = new MongoClient();
    var database = client.GetDatabase("HamsterSchool");
    var collection = database.GetCollection<Hamster>("Hamsters");
    await collection.Indexes.CreateOneAsync(Builders<Hamster>.IndexKeys.Ascending(_ => _.Name));
}
posted @ 2017-02-15 17:40  94cool  阅读(813)  评论(0编辑  收藏  举报