Beispiel #1
0
        public static void Add(Person t)
        {
            //创建数据连接

            MongoServer server = new MongoClient(conn).GetServer() ;
            //获取指定数据库
            MongoDatabase db = server.GetDatabase(dbName);
            //获取表
            MongoCollection col = db.GetCollection(tbName);
            //插入
            WriteConcernResult result =  col.Insert(t);
        }
Beispiel #2
0
        public static void Update(Person t)
        {
            //创建数据连接
            MongoServer server = new MongoClient(conn).GetServer();
            //获取指定数据库
            MongoDatabase db = server.GetDatabase(dbName);
            //获取表
            MongoCollection<Person> col = db.GetCollection<Person>(tbName);

            BsonDocument bd = BsonExtensionMethods.ToBsonDocument(t);

            IMongoQuery query = Query.EQ("_id", t.Id);

            col.Update(query, new UpdateDocument(bd));
        }
Beispiel #3
0
 static void Main(string[] args)
 {
     Person p = new Person();
     p.Age = 12;
     p.Name = "lisi";
     p.Id = "1";
     //Add(p);
        // SelectAll();
     Update(p);
 }