Mongoose find users with a field?

Viewed 162

Good day everyone!

I have a pretty simple question. Here is my schema:

const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({
    userid: {
        type: String,
        required: true
    },
    balance: {
        type: Number,
        default: 0,
        required: true
    },
    clearance: {
        type: Number,
        required: false
    }
})

module.exports = mongoose.model('User', userSchema)

All I want is to be able to find all users that HAVE the field. So anyone with ANY clearance would be put on a list, regardless of the actual number. I know how to find users by their id's or their balance, but I don't know how to find users based on just having the field alone.

1 Answers
Related