mongodb get distinct records

后端 未结 6 1216
栀梦
栀梦 2020-11-29 06:33

I am using mongoDB in which I have collection of following format.

{\"id\" : 1 , name : x  ttm : 23 , val : 5 }
{\"id\" : 1 , name : x  ttm : 34         


        
6条回答
  •  甜味超标
    2020-11-29 07:05

    Specify Query with distinct. The following example returns the distinct values for the field sku, embedded in the item field, from the documents whose dept is equal to "A":

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

    Reference: https://docs.mongodb.com/manual/reference/method/db.collection.distinct/

提交回复
热议问题