可以通过下列代码创建一个collection:

            MongoClient client = new MongoClient(BuildConnectionString());
            MongoServer server = client.GetServer();
            
            MongoDatabase dotNetDatabase = server.GetDatabase(@"dotNetDatabase");
            MongoCollection dotNetCollection = dotNetDatabase.GetCollection(@"dotNetCollection");
            table1 dataTable = new table1();
            dataTable.testCol1 = "aaa";
            dotNetCollection.Insert<table1>(dataTable);

其中table1为自定义的entity。这里要记住一点,若没有insert record那对应的collection以及database是不会被创建的。仅仅Get方法是无法创建对应的collection以及database的。

 

posted on 2014-07-07 11:23  筷子王老吉  阅读(161)  评论(0编辑  收藏  举报