Skip to main content

Is there a way to get only User item from a collection using Mongoose DB?

So this is my Schema folder:

module.exports = mongoose.model(
    'premium', 
    new mongoose.Schema({
        User: String,
        Name: String,
        Expire: Number,
        Permanent: Boolean,
    })
);

So I want to get from database only User and Name items and use it in embed on discord.js, but I am not finding any way to do so

Answer

You can use select and specify field you want with 1 and not with 0 :

dbSchemas.SomeValue.find({}).select({ "User": 1, "Name": 1});

Comments