# How to query documents where value is not null in Mongoose

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

> A quick guide to learning how to use the $ne operator to query documents where the value is not null in Mongoose.

MongoDB provides the `$ne` operator to select documents where the field value is not equal to the specified value. It also includes documents that do not contain the field.

The following example demonstrates how you can use the `$ne` operator to [find documents](https://attacomsian.com/blog/mongoose-find-documents) where the value of the `role` field is not `null`:

```javascript
const mongoose = require('mongoose')
const { Schema } = mongoose

const User = mongoose.model(
  'User',
  new Schema({
    name: String,
    role: String
  })
)

const users = await User.find({ role: { $ne: null } })
```

There is another operator called `$nin` that selects the documents where the field value is not in the specified array or the field does not exist.

Here is how you can use `$nin` to find all users that are not `admin` and `owner`:

```javascript
const users = await User.find({ role: { $nin: ['admin', 'owner'] } })
```
