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<usera>("user", query);
IEnumerable<usera> u = MongoDBHelper.GetAll<usera>("user").Distinct<usera>(new ModelComparer()); //usera u = MongoDBHelper.GetOne<usera>("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<usera>
{
public bool Equals(usera x, usera y)
{
return x.name.ToUpper() == y.name.ToUpper();
}
public int GetHashCode(usera obj)
{
return obj.name.ToUpper().GetHashCode();
}
}
}

  

去重mongodb LIST的更多相关文章

  1. mongodb篇二:mongodb克隆远程数据库,去重查询的命令及对应java语句

    http://blog.csdn.net/qkxh320/article/details/16115671 1.首先操作mongodb最基本命令:: show databases;           ...

  2. 【解决】MongoDB 线上业务处理,数据去重脚本实现

    mongo客户端工具下载  https://robomongo.org/download   线上业务,k线 展示出现问题,相同时间戳的数据多次插入导致数据不真实,后经排查发现是每次都是写的四条数据, ...

  3. mongodb distinct去重

    MongoDB的destinct命令是获取特定字段中不同值列表.该命令适用于普通字段,数组字段和数组内嵌文档. mongodb的distinct的语句: db.users.distinct('last ...

  4. mongodb多字段去重

    单字段去重 db.student.distinct("name"); 多字段去重 db.student.aggregate([{      $group:{            ...

  5. MongoDB去重

    db.集合.aggregate([ { $group: { _id: {字段1: '$字段1',字段2: '$字段2'},count: {$sum: 1},dups: {$addToSet: '$_i ...

  6. MongoDB数据库去重

    查询: db.patents_texts.aggregate([ { $group:{_id:{Patent_num:'$Patent_num',Patent_name:'$Patent_name'} ...

  7. MongoDB基础命令笔记

    一.创建数据库 use foobar 二.创建集合 db.persons.insert({name:"zhaomin",age:23}) 三.查找 db.persons.find( ...

  8. MongoDB常用命令

    本文整理了一年多以来我常用的MongoDB操作,涉及mongo-shell.pymongo,既有运维层面也有应用层面,内容有浅有深,这也就是我从零到熟练的历程. MongoDB的使用之前也分享过一篇, ...

  9. MongoDB学习笔记~管道中的分组实现group+distinct

    回到目录 mongoDB的管道是个好东西,它可以将很多操作批处理实现,即将多个命令放入一个管道,然后去顺序的执行它们,今天我要说的是,利用管道中的分组来实现实现中的ditinct+group的效果,即 ...

随机推荐

  1. appium+python自动化58-xpath定位

    基本属性定位 以淘宝app为例,定位左上角扫一扫按钮 1.可以通过text文本定位到 //*[@text='text文本属性'] # 定位text driver.find_element_by_xpa ...

  2. lua中遍历table的几种方式比较

    当我在工作中使用lua进行开发时,发现在lua中有4种方式遍历一个table,当然,从本质上来说其实都一样,只是形式不同,这四种方式分别是: for key, value in pairs(tbtes ...

  3. ARC中的@autoreleasepool还有作用吗?

    ARC中的@autoreleasepool还有作用吗? QUESTION For the most part with ARC (Automatic Reference Counting), we d ...

  4. Android RadioButton设置选中时文字和背景颜色同时改变

    主要应用在购物车,像淘宝的那样,点击以后弹出一个选择种类颜色这样的popuwindow以后,然后这个选择种类的地方要用到类似这个玩意儿. 搜了一下,效果和这个文章一致.转了. 原文地址:http:// ...

  5. easyui datagrid如何获取到每行的文本框

    在return '<input type="text" name="txtCount" class="inputvalue"/> ...

  6. Python学习(五)函数 —— 内置函数 lambda filter map reduce

    Python 内置函数 lambda.filter.map.reduce Python 内置了一些比较特殊且实用的函数,使用这些能使你的代码简洁而易读. 下面对 Python 的 lambda.fil ...

  7. iOS: xcode打包上传iTunes失败,iTunes Store operation failed,this action can not complete .try again

    通过xcode点击“upload to app store”上传到itunes,结果一直提示“itunes store operation failed” 原因:网速的问题,我之前也遇到过,网速好的时 ...

  8. go语言基础之回调函数

    1.回调函数 示例: 实现:加,减,乘 示例: package main import "fmt" type FuncType func(int, int) int //实现加法 ...

  9. springMVC之增删改查

    一.核心原理 1. 用于发送请求给server: /home.htm 2. 请求被DispatchServlet拦截到 3. DispatchServlet通过HandleMapping检查url有没 ...

  10. (剑指Offer)面试题41:和为s的连续正数序列

    题目: 输入一个正数s,打印出所有和为s的连续正数序列(至少含有两个数).例如输入15,由于1+2+3+4+5=4+5+6=7+8=15,所以结果打印出3个连续序列1-5,,4-6和7-8. 思路: ...