Exemplo n.º 1
0
        /// <summary>
        /// 删除文档的Demo
        /// </summary>
        public void DeleteDemo()
        {
            IMongoDBOperation <firstCol> firstCol = new MongoDBHelper <firstCol>();
            //定义获取“Name”值为“test”的查询条件
            var query = new QueryDocument {
                { "title", "度娘" }
            };

            firstCol.Delete(typeof(firstCol).Name, query);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 插入文档的Demo
        /// </summary>
        public void InsertDemo()
        {
            IMongoDBOperation <firstCol> firstCol = new MongoDBHelper <firstCol>();
            firstCol model = new firstCol()
            {
                url         = "www.baidu.com",
                title       = "百度",
                tags        = new string[] { "网站", "好好" },
                by          = "Cyrus",
                likes       = 0.12,
                description = "哈哈,葫芦娃!"
            };

            firstCol.Insert(model.GetType().Name, model);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 更新文档的Demo
        /// </summary>
        public void UpdateDemo()
        {
            IMongoDBOperation <firstCol> firstCol = new MongoDBHelper <firstCol>();
            //定义获取“title”值为“百度”的查询条件
            var query = new QueryDocument {
                { "title", "度娘" }
            };
            //定义更新文档
            var update = new UpdateDocument {
                { "$set", new QueryDocument {
                      { "title", "百度" }
                  } }
            };

            firstCol.Update(typeof(firstCol).Name, query, update);
        }