博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
去重mongodb LIST
阅读量:6343 次
发布时间:2019-06-22

本文共 3154 字,大约阅读时间需要 10 分钟。

using MongoDB;using DockSample.DB;using MongoDB.Driver;using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.IO;using System.Linq;using System.Text;using System.Windows.Forms;using WeifenLuo.WinFormsUI.Docking;using MongoDB.Bson;namespace DockSample{    public partial class Form2 : DockContent    {        public Form2()        {            InitializeComponent();        }        // workaround of RichTextbox control's bug:        // If load file before the control showed, all the text format will be lost        // re-load the file after it get showed.        private bool m_resetText = true;        protected override void OnPaint(PaintEventArgs e)        {            base.OnPaint(e);            if (m_resetText)            {                m_resetText = false;            }        }        protected override string GetPersistString()        {            // Add extra information into the persist string for this document            // so that it is available when deserialized.            return GetType().ToString() + ",1123," + Text;        }        private void menuItem2_Click(object sender, System.EventArgs e)        {            MessageBox.Show("This is to demostrate menu item has been successfully merged into the main form. Form Text=" + Text);        }        private void menuItemCheckTest_Click(object sender, System.EventArgs e)        {        }        protected override void OnTextChanged(EventArgs e)        {            base.OnTextChanged(e);        }            private void button1_Click(object sender, EventArgs e)        {            usera u = new usera();            u.cid = 10;            u.name = "测试看看";            WriteConcernResult s = MongoDBHelper.InsertOne("user", u);            label1.Text = s.DocumentsAffected.ToString() + "------" + s.HasLastErrorMessage.ToString();//s.HasLastErrorMessage=false既是表示操作成功!        }        private void button2_Click(object sender, EventArgs e)        {            IMongoQuery query = MongoDB.Driver.Builders.Query.EQ("cid", 9);           // usera u = MongoDBHelper.GetOne
("user", query); IEnumerable
u = MongoDBHelper.GetAll
("user").Distinct
(new ModelComparer()); //usera u = MongoDBHelper.GetOne
("user", "555993c18825b905c8879edc"); //label1.Text = u.cid.ToString() + "---" + u.name; foreach(usera ua in u) { richTextBox1.AppendText(ua.cid.ToString() + "--" + ua.name + "\r\n"); } } private void button3_Click(object sender, EventArgs e) { MongoDBHelper.DeleteAll("user"); } } public class usera { public ObjectId id { get; set; } public int cid { get; set; } public string name { get; set; } } public class ModelComparer : IEqualityComparer
{ public bool Equals(usera x, usera y) { return x.name.ToUpper() == y.name.ToUpper(); } public int GetHashCode(usera obj) { return obj.name.ToUpper().GetHashCode(); } }}

  

转载地址:http://elkla.baihongyu.com/

你可能感兴趣的文章
Windows Server 2012 将资源发布到 AD DS
查看>>
Redhat linux C 函数 以及一些shell命令的 man rpm
查看>>
XenServer 6.0发布
查看>>
提高工作效率的方法之“20分钟理论”
查看>>
docker CE&&EE版本centos安装
查看>>
浅谈URL生成方式的演变
查看>>
Linux下ssl+http 实现 HTTPS 访问服务器设置
查看>>
磁盘与文件系统管理之五
查看>>
python学习-递归
查看>>
day:35:netfilter防火墙的管理工具firewalld及iptables备份恢复
查看>>
第六讲:用户界面 View(二)
查看>>
lsof用户及恢复日志文件
查看>>
Python之获取系统信息--(二)
查看>>
IE9,IE10不能显示@font-face定义的字体
查看>>
JSP----ISPI
查看>>
oracle 归档日志满了如何处理
查看>>
虚函数
查看>>
jsp当中引入静态文件
查看>>
登陆框post注入教程
查看>>
maven打包
查看>>