去重mongodb LIST
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的更多相关文章
- mongodb篇二:mongodb克隆远程数据库,去重查询的命令及对应java语句
http://blog.csdn.net/qkxh320/article/details/16115671 1.首先操作mongodb最基本命令:: show databases; ...
- 【解决】MongoDB 线上业务处理,数据去重脚本实现
mongo客户端工具下载 https://robomongo.org/download 线上业务,k线 展示出现问题,相同时间戳的数据多次插入导致数据不真实,后经排查发现是每次都是写的四条数据, ...
- mongodb distinct去重
MongoDB的destinct命令是获取特定字段中不同值列表.该命令适用于普通字段,数组字段和数组内嵌文档. mongodb的distinct的语句: db.users.distinct('last ...
- mongodb多字段去重
单字段去重 db.student.distinct("name"); 多字段去重 db.student.aggregate([{ $group:{ ...
- MongoDB去重
db.集合.aggregate([ { $group: { _id: {字段1: '$字段1',字段2: '$字段2'},count: {$sum: 1},dups: {$addToSet: '$_i ...
- MongoDB数据库去重
查询: db.patents_texts.aggregate([ { $group:{_id:{Patent_num:'$Patent_num',Patent_name:'$Patent_name'} ...
- MongoDB基础命令笔记
一.创建数据库 use foobar 二.创建集合 db.persons.insert({name:"zhaomin",age:23}) 三.查找 db.persons.find( ...
- MongoDB常用命令
本文整理了一年多以来我常用的MongoDB操作,涉及mongo-shell.pymongo,既有运维层面也有应用层面,内容有浅有深,这也就是我从零到熟练的历程. MongoDB的使用之前也分享过一篇, ...
- MongoDB学习笔记~管道中的分组实现group+distinct
回到目录 mongoDB的管道是个好东西,它可以将很多操作批处理实现,即将多个命令放入一个管道,然后去顺序的执行它们,今天我要说的是,利用管道中的分组来实现实现中的ditinct+group的效果,即 ...
随机推荐
- Appium+python自动化21-DesiredCapabilities详解
Appium Desired Capabilities Desired Capabilities 是由 keys 和 values 组成的 JSON 对象. 举个简单例子: { "platf ...
- ExtJs4.0日期控件只显示年月按年月格式会跳月的解决办法
如果是Ext.form.panel的话,只要设置一下属性就可以.如下代码: { text : '期间', width : 80, sortable : true, dataIndex : 'accou ...
- Storm和Spark Streaming框架对比(转)
原文链接:Storm和Spark Streaming框架对比 Storm和Spark Streaming两个都是分布式流处理的开源框架.但是这两者之间的区别还是很大的,正如你将要在下文看到的. 处理模 ...
- windows服务器提权前请先执行systeminfo命令
pr.巴西烤肉 对应补丁 好多朋友见到Windows服务器就祭出pr.巴西烤肉一气搞,忙完免杀又忙找可写目录,最后发现服务器打上了对应的补丁.笔者在提权前都会执行systeminfo命令,查看对应补丁 ...
- 如何配置通过Fiber Channel连接主机与存储
在一台Windows Client上, 安装免费的Cisco Fabric Manager. 笔者安装的是Fabric Manager 5.0(7). 注意, 这台Windows Client上应该安 ...
- Sqlserver 中添加数据库登陆账号并授予数据库所有者权限
Sqlserver 中添加数据库登陆账号并授予数据库所有者权限 USE master GO --通过sp_addlogin创建登录名 --DEMO:登陆账号 --123456:登陆密码 ' --切换数 ...
- SqlServer 删除重复记录
在给一个客户上线的系统里发现有一张表里出现了重复的数据,结果通过排查代码发现确实业务逻辑有问题,在修改了代码后需要将为数据库里的重复数据删除 在CSDN上找到解决方案,对线上的数据库尽量不要执行删除操 ...
- android中listview点击事件失效的灵异事件
首先说明一下我想实现的功能: 点击某个item之后,让其颜色发生变化.如果变化网上有很多例子,我就不班门弄斧了.Listview之所以点击没有反应是因为上图中绿色部分(自己定义的一个继承BaseAda ...
- UNIX网络编程读书笔记:poll函数
poll函数提供的功能与select类似,不过在处理流设备时,它能够提供额外的信息. poll函数原型 #include <poll.h> int poll(struct pollfd * ...
- Ext.encode 与 Ext.decode .
Ext.encode( Mixed o ) : String: json对象转换json字符串 Ext.decode( String json ) : Object: json字符串转换json对象 ...