private static void Log(MongoDatabase database)
        {
            var createOptions = CollectionOptions
                                .SetCapped(true)
                                .SetMaxSize(5000)
                                .SetMaxDocuments(10000);

            createOptions.SetCapped(true);
            createOptions.SetMaxDocuments(5000);
            createOptions.SetMaxSize(10000);


            if (!database.CollectionExists("site.log"))
            {
                database.CreateCollection("site.log", createOptions);
            }

            var logCollection = database.GetCollection("site.log");
            var logIndexes    = logCollection.GetIndexes();

            if (logIndexes.All(c => c.Name != "CreateDate"))
            {
                var keys    = IndexKeys.Ascending("CreateDate");
                var options = IndexOptions.SetName("CreateDate");
                logCollection.CreateIndex(keys, options);
            }
        }
Exemple #2
0
 private MongoDB.Driver.MongoCollection getMongoCollection(string collection)
 {
     MongoDB.Driver.MongoDatabase mongoDataBase = getMongoServer();
     if (!mongoDataBase.CollectionExists(collection))
     {
         mongoDataBase.CreateCollection(collection);
     }
     MongoDB.Driver.MongoCollection mongoCollection = mongoDataBase.GetCollection(collection);//选择集合,相当于表
     return(mongoCollection);
 }