I am trying to loop through all the documents in a collection in mongodb.
Here is what I have.
module.exports = {
name: `store`,
aliases:['shop'],
/**
* @param {Client} client
* @param {Message} message
* @param {String[]} args
*/
run: async(client, message, args) => {
const exampleEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Boblox Shop')
.setDescription('Buy stuff with $buy <id>')
const items = require('./shop')
items.find({}).then(function(documents) {
documents.forEach(function(u) {
exampleEmbed.addField(`${u.ItemName}`, `Price: ${u.Price}`)
});
})
.setTimestamp()
}
}
Shop is a schema. Here is the code for shop
const mongoose = require("mongoose")
const commandsRan = mongoose.Schema({
ItemName:String,
Price:Number,
Stock:Number,
Rarity:String,
Description:String,
Emoji:String
})
module.exports = mongoose.model("Shop", commandsRan, 'shopitems')
When I run the code shop command, I get this error: TypeError: items.find(...).then(...).setFooter is not a function
How do I loop through every document in the collection and add a field to the embed?