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()函数 ...
随机推荐
- AJAX在VS2005中的简单应用 使用ajaxpro.2.dll[点击按钮执行事件不刷新]
原文发布时间为:2008-10-21 -- 来源于本人的百度文章 [由搬家工具导入] 1.下載ajaxpro.dll或AjaxPro.2.dll 放在Bin文件夹中2.配置web.config 3.u ...
- 解决Spring在线程中注入为空指针的问题
在启用线程中使用来jdbcTemplate来查询数据库,引入jdbcTemplate是用Spring @Autowired注解 方式引入,但是在运行中 jdbcTemplate 总是 空指针 解决 ...
- hdu 4990(数学,等比数列求和)
Reading comprehension Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- Linux每日一坑001
centos6,7中网卡/etc/sysconfig/network-scripts/ifcfg-eth0的命名是有要求的,必须是ifcfg-开头.改网卡名的时候掉坑.
- webservice原理及基于cxf开发的基本流程
一.SOA和webservice SOA(service-Oriented Architecture)是面向服务的架构,是一个组件模型,它将应用程序的不同功能单元(称为服务)通过这些服务之间定义良好的 ...
- Sharing Cookies --AtCoder
题目描述 Snuke is giving cookies to his three goats.He has two cookie tins. One contains A cookies, and ...
- ActiveMQ 翻译第一章 1.2小节(松耦合与ActiveMQ和何时使用ActiveMQ)
第一章 1.2.1小节 松耦合与ActiveMQ ActiveMQ为应用程序架构提供送耦合实现组件.松耦合经常被引入到系统架构中,来减轻紧耦合的远程工程调用的使用.松耦合的设计是异步的,来自其他系统 ...
- 2016北京集训测试赛(十四)Problem A: 股神小L
Solution 考虑怎么卖最赚钱: 肯定是只卖不买啊(笑) 虽然说上面的想法很扯淡, 但它确实能给我们提供一种思路, 我们能不买就不买; 要买的时候就买最便宜的. 我们用一个优先队列来维护股票的价格 ...
- WebStorm添加多个项目到当前工程目录
File-> Settings -> Directories -> Add Content Root,选择你要加入的Project 点击OK -> Apply -> OK ...
- PHP 5.4 中经 htmlspecialchars 转义后的中文字符串为空的问题
PHP 5.4.3 环境中测试了一个在 PHP 5.2 环境下运行正常的程序,却发现本应正常提交一个中文字符串到数据库的代码却提交了一个空字符串,经过排查,该字符串在经 htmlspecialchar ...