去重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的效果,即 ...
随机推荐
- 用 Nokitjs 解决前端开发中的跨域问题
问题 在开发一些「单页应用」时,通常会使用 Ajax 和服务器通讯,比如 RESTful API,通常「前端」和「服务端 API」可能是有不同人员在负责,也不在同一个工程下,那么开发过程中就可能会遇到 ...
- [Android Pro] Android 必知必会-使用 supportV4 的 RoundedBitmapDrawable 实现圆角
RoundedBitmapDrawable 是 supportV4 下的一个类,有了它,显示圆角和圆形图片的情况下就不需要额外的第三方类库了,还能和各种图片加载库配合使用. 背景 今天无意间看到一段实 ...
- [Linux] ubuntu server sudo出现sudo:must be setuid root 完美解决办法
1.开机按shift或esc先进行recovery模式 2.选择root命令行模式 3.先执行 #mount -o remount,rw / 这个很重要,网上找的很多资料都不全没有这步造成无法恢复成功 ...
- Single Number and Single Number II
[] Given an array of integers, every element appears twice except for one. Find that single one. [] ...
- @Redis Desktop Manager无法连接虚拟机中启动的redis服务问题解决
Redis Desktop Manager下载地址 https://redisdesktop.com/download 安装好以后连接linux服务器上的Redis服务器错误: 问题排查: 1.检查R ...
- CUDA使用Event进行程序计时
GPGPU是众核设备,包含大量的计算单元,实现超高速的并行. 使用CUDA在nvidia显卡上面编程时,可以使用CUDA提供的Event进行程序计时. 当然,每种编程语言基本都提供了获取系统时间的函数 ...
- mahout运行测试与kmeans算法解析
在使用mahout之前要安装并启动hadoop集群 将mahout的包上传至linux中并解压即可 mahout下载地址: 点击打开链接 mahout中的算法大致可以分为三大类: 聚类,协同过滤和分类 ...
- php stdClass 的使用
原文:http://www.php.cn/php-weizijiaocheng-371767.html ------------------------------------------------ ...
- Linux ${} 变量内容的提取和替换功能等
[root@localhost log]# var=/dir1/dir2/file.txt 1.对变量取值 [root@localhost log]# echo ${var} /dir1/dir2/f ...
- PHP快速入门 如何操作MySQL
1 创建一个新的数据库,注意类型设置为utf8_general_ci 2 在数据库中创建一个新的表,比如叫做tg_user(先从左侧选择刚才创建的数据库) 3 创建第一个字段,自动编号.我们估计网站的 ...