mongodb distinct去重
MongoDB的destinct命令是获取特定字段中不同值列表。该命令适用于普通字段,数组字段和数组内嵌文档.
mongodb的distinct的语句:
db.users.distinct('last_name')
等同于 SQL 语句:
select DISTINCT last_name from users
表示的是根据指定的字段返回不同的记录集。
一个简单的实例:

//

> db.addresses.insert({"zip-code": 10010})

> db.addresses.insert({"zip-code": 10010})

> db.addresses.insert({"zip-code": 99701})


> // shell helper:

> db.addresses.distinct("zip-code");

[ 10010, 99701 ]


> // running as a command manually:

> db.runCommand( { distinct: 'addresses', key: 'zip-code' } )

{ "values" : [ 10010, 99701 ], "ok"

//

> db.comments.save({"user": {"points": 25}})

> db.comments.save({"user": {"points": 31}})

> db.comments.save({"user": {"points": 25}})


> db.comments.distinct("user.points");

[ 25, 31 ]
mongodb distinct去重的更多相关文章
- Linq 中的distinct去重
Linq的Distinct和T-Sql的distinct一样,可以将重复的结果集去重注意: 1 distinct去重记录要求每个字段都重复时,才算重复对象,这与sql一样2 distinct语句可以和 ...
- 存储过程系列三:根据表别名方式distinct去重插入
1.根据表别名方式distinct去重插入 insert into GG_XKZ_YLQXSCXKESL_SCDZ ( bzj, xkzid, sqid, jtdz, szsf, ...
- .NET-list扩展方法Distinct去重
原文链接:https://blog.csdn.net/daigualu/article/details/70800012 .NET中list的扩展方法Distinct可以去掉重复的元素,分别总结默认去 ...
- .Net Collection Distinct 去重
由于业务场景的需要,海量的数据需要进行处理.组装,难免会出现冗余的重复数据.如何处理重复的数据就是一个问题. 简单的集合中,去重就可以用linq distinct来完成.对于复杂的集合直接使用dist ...
- postgresql中使用distinct去重
select语法 [ WITH [ RECURSIVE ] with_query [, ...] ] SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ...
- List<object>进行Distinct()去重
有时我们会对一个list<T>集合里的数据进行去重,C#提供了一个Distinct()方法直接可以点得出来.如果list<T>中的T是个自定义对象时直接对集合Distinct是 ...
- DISTINCT 去重仍有重复的分析
logger日志报错 插入数据时违反主键唯一约束 org.springframework.dao.DuplicateKeyException: ### Error updating database. ...
- C# Distinct去重泛型List
List<int>去重 List<string>去重 List<T>去重 1. List<int>去重 List<int> ilist = ...
- 关于Django中的数据库操作API之distinct去重的一个误传
转载自http://www.360doc.com/content/18/0731/18/58287567_774731201.shtml django提供的数据库操作API中的distinct()函数 ...
随机推荐
- 调试UPX压缩的notepad
@date: 2016/11/29 @author: dlive 0x01 运行时压缩 对比upx压缩前后的notepad可以看到如下特点 PE头的大小一样 节区名称改变(.text -> .U ...
- asp.net内置对象 Response对象使用介绍
Response对象是HttpRespone类的一个实例.该类主要是封装来自ASP.NET操作的HTTP相应信息.Response对象将数据作为请求的结果从服务器发送到客户浏览器中,并提供有关响应的消 ...
- hdu 4520
小Q系列故事——最佳裁判 Time Limit: 500/200 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...
- 转载——Java与WCF交互(一):Java客户端调用WCF服务
最近开始了解WCF,写了个最简单的Helloworld,想通过java客户端实现通信.没想到以我的基础,居然花了整整两天(当然是工作以外的时间,呵呵),整个过程大费周折,特写下此文,以供有需要的朋友参 ...
- 使用dvajs+webpack构建react开发环境
之前我有写过博文介绍过dva.js及其用法,dva.js固然是个非常优秀的框架,但是如果用dev-cli来创建的话就会默认绑定使用roadhog而不是webpack.鉴于roadhog的文档要明显少于 ...
- Nowcoder Girl 参考题解【待写】
[官方题解]:https://www.nowcoder.com/discuss/65411?toCommentId=1134823 [题目链接]:https://www.nowcoder.com/te ...
- 10.1综合强化刷题 Day5
T1 拼不出的数 lost.in/.out/.cpp[问题描述]3 个元素的集合{5; 1; 2}的所有子集的和分别是0; 1; 2; 3; 5; 6; 7; 8.发现最小的不能由该集合子集拼出的数字 ...
- POJ 3321 Apple Tree 树状数组+DFS
题意:一棵苹果树有n个结点,编号从1到n,根结点永远是1.该树有n-1条树枝,每条树枝连接两个结点.已知苹果只会结在树的结点处,而且每个结点最多只能结1个苹果.初始时每个结点处都有1个苹果.树的主人接 ...
- Word Break - LeetCode
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...
- python的列表元组字典集合比较
定义 方法 列表 可以包含不同类型的对象,可以增减元素,可以跟其他的列表结合或者把一个列表拆分,用[]来定义的 eg:aList=[123,'abc',4.56,['inner','list'],7- ...