• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
成为自己最想成为的那种人
博客园    首页    新随笔    联系   管理    订阅  订阅
Mongo 查询(可视化工具)

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"} } )

 

posted on 2018-11-16 15:31  遇见未来  阅读(855)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3