# How to query for distinct values in Mongoose

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Jul 11, 2022. Topics: Node.js, Mongoose, MongoDB.
Canonical URL: https://attacomsian.com/blog/mongoose-distinct

> A quick guide to learning how to select distinct values in a MongoDB collection using Mongoose.

In Mongoose, the [`Model` class](https://attacomsian.com/blog/mongoose-models) provides the `distinct()` method to get all the unique values for a specific field. 

Here is an example that demonstrates how to use the `distinct()` method to find unique URLs:

```javascript
const mongoose = require('mongoose')

const Link = mongoose.model('Link', { url: String, clicks: Number })

const urls = await Link.distinct('url')
```

The `distinct()` method also accepts a filter object to restrict unique results:

```javascript
const urls = await Link.distinct('url', { clicks: { $gt: 100 } })
```
