首页 > 其他 > 详细

Mongo 查询(可视化工具)

时间:2018-11-16 15:45:07      阅读:174      评论:0      收藏:0      [点我收藏+]

distinct

  MongoDB 的 distinct 命令是获取特定字段中不同值列表的最简单工具。

  该命令适用于普通字段、数组字段以及数组内嵌文档(集合对象)。

  db.getCollection(customer).distinct("customer_type")
  // chances字段的值是个集合,获取集合内每个对象的opportunitytype字段的值域
  db.getCollection(customer).distinct("chances.opportunitytype")

  统计某几个人的共同好友:

  db.person.distinct("myFriends", {"manName" : {"$in" : ["ZhenQin""YangYan"]}})

  使用 runCommand 命令来写:

    下面的示例返回 inventory 集合的 dept 字段的值域:

   db.runCommand ( { distinct: "inventory", key: "dept" } )

    下面的示例返回 inventory 集合中 dept 取值为 "A" 的结果集中的 “item.sku” 字段的值域:

   db.runCommand ( { distinct: "inventory", key: "item.sku", query: { dept: "A"} } )

 

Mongo 查询(可视化工具)

原文:https://www.cnblogs.com/zhangchaoran/p/9969610.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!