去重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的效果,即 ...
随机推荐
- 独立成分分析 与 功能连接之间的关联尝试 by 张高燕
在处理fMRI数据时,使用空间ICA的方法. 将一个四维的fMRI数据分解为空间pattern与时间序列的乘积. //这里的pattern=component 其中每一pattern的时间序列 ...
- 数学图形(2.17)pappus螺线
帕波斯(Pappus of Alexandria) 生于亚历山大,活跃于公元300—350前后.该螺线是一种绕在圆锥上的曲线. #http://www.mathcurve.com/courbes3d/ ...
- 数学图形(1.25)cassini曲线
通过这种曲线可以看到一种由8到0的过度 相关软件参见:数学图形可视化工具,使用自己定义语法的脚本代码生成数学图形.该软件免费开源.QQ交流群: 367752815 #http://www.mathcu ...
- 科普:UTF-8 GBK UTF8 GB2312 之间的区别和关系
UTF-8:Unicode TransformationFormat-8bit,允许含BOM,但通常不含BOM.是用以解决国际上字符的一种多字节编码,它对英文使用8位(即一个字节),中文使用24为(三 ...
- liunx修改字体为宋体
有找到修改Linux默认字体的方法sudo vi /etc/fonts/conf.d/69-language-selector-zh-cn.conf修改下sans-serif相关设定 <m ...
- 第三章 线程安全的DateFormat工具类
1.使用threadLocal包装DateFormat(太复杂,不推荐) 2.使用org.apache.commons.lang3.time.DateFormatUtils下的方法(推荐) DateF ...
- 关闭使用ShellExecute打开的进程!!!!!
前言: 最近做一个项目使用到ShellExecute来打开一个带参数的外部exe文件,关闭时遇到不少问题,最终解决,总结如下. 对于关闭ShellExecute打开的进程窗口,网上比较多的是用Find ...
- 高性能WEB开发:重排与重绘
DOM编程可能最耗时的地方,重排和重绘. 1.什么是重排和重绘 浏览器下载完页面中的所有组件——HTML标记.JavaScript.CSS.图片之后会解析生成两个内部数据结构——DOM树和渲染树. D ...
- [C#.NET] X509 數位電子簽章
摘自: http://www.dotblogs.com.tw/yc421206/archive/2012/06/30/73140.aspx 在上篇[C#.NET] 字串及檔案,利用 RSA 演算法加解 ...
- 【架构】OpenResty相关资料
OpenResty最佳实践 在2012年的时候,我加入到奇虎360公司,为新的产品做技术选型.由于之前一直混迹在python圈子里面,也接触过nginx c模块的高性能开发,一直想找到一个兼备pyth ...