去重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的效果,即 ...
随机推荐
- android中共享全局数据的方法
转自:http://blog.csdn.net/ameyume/article/details/6100756 我们在平时的开发中,有时候可能会需要一些全局数据,来让应用中的所有Activity和Vi ...
- Singleton 单例模式(懒汉方式和饿汉方式)
单例模式的概念: 单例模式的意思就是只有一个实例.单例模式确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例.这个类称为单例类. 关键点: 1)一个类只有一个实例 这是最基本 ...
- 进程控制块(PCB)结构
一.进程控制块(PCB)结构 进程控制块(PCB)是系统为了管理进程设置的一个专门的数据结构.系统用它来记录进程的外部特征,描述进程的运动变化过程.同时,系统可以利用PCB来控制和管理进程,所以说,P ...
- Fragment 简介 基础知识 总结 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- Spark学习散点总结
使用Spark 时,通常会有两种模式.一.在交互式编程环境(REPL, a.k.a spark-shell)下实现一些代码,测试一些功能点.二.像MapReduce 那样提前编写好源代码并编译打包(仅 ...
- 转:美团Android资源混淆保护实践
转自:http://tech.meituan.com/mt-android-resource-obfuscation.html 前言 Android应用中的APK安全性一直遭人诟病,市面上充斥着各种被 ...
- Java项目在jsp页面中引入jquery框架的步骤
环境:在Java web项目中引入juqery框架 工具:MyEclipse8.5 [步骤如下] A:新建一个Java web项目TestJquery,在WebRoot目录下创建一个jquery文件 ...
- php的opcache缓存扩展(php页面代码刷新速度)
opcache (全程 zend opcache): 从php5.5开始,默认提供的php脚本缓存扩展,编译php5.5时加上参数--enable-opcache就可以编译opcache了,只是要启用 ...
- LeetCode_Path Sum
一.题目 Path Sum My Submissions Given a binary tree and a sum, determine if the tree has a root-to-leaf ...
- selenium webdriver 的三种等待方式
1.显式等待 一个显式等待是你定义的一段代码,用于等待某个条件发生然后再继续执行后续代码. from selenium import webdriver from selenium.webdriver ...