发布于 2015-09-14 14:57:27 | 177 次阅读 | 评论: 0 | 来源: 网络整理

db.collection.distinct()

The db.collection.distinct() method finds the distinct values for a specified field across a single collection and returns the results in an array. The method accepts the following argument:

参数:
  • field (string) – Specifies the field for which to return the distinct values.
  • query (document) – Specifies the selection query to determine the subset of documents from which to retrieve the distinct values.

注解

Consider the following examples of the db.collection.distinct() method:

  • Return an array of the distinct values of the field ord_dt from all documents in the orders collection:

    db.orders.distinct( 'ord_dt' )
    
  • Return an array of the distinct values of the field sku in the subdocument item from all documents in the orders collection:

    db.orders.distinct( 'item.sku' )
    
  • Return an array of the distinct values of the field ord_dt from the documents in the orders collection where the price is greater than 10:

    db.orders.distinct( 'ord_dt',
                        { price: { $gt: 10 } }
                      )
    
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务