'Content/map is undefined

Let's say I have this:

 const db = require('../../Models/warns')
const { Message, MessageEmbed } = require('discord.js')
const reason = args.slice(1).join(" ")
            db.findOne({ guildid: message.guild.id, user: user.user.id}, async(err, data) => {
                if(err) throw err;
                if(!data) {
                    data = new db({
                        guildid: message.guild.id,
                        user : user.user.id,
                        content : [
                            {
                                moderator : message.author.id,
                                reason : reason
                            }
                        ]
                    })
                } else {
                    const obj = {
                        moderator: message.author.id,
                        reason : reason
                    }
                    data.content.push(obj)
                }
                data.save()
            });

Why is push undefined (TypeError: Cannot read properties of undefined (reading 'push'))? Is there anything I am missing?

Same thing goes if I have this:

const sembed = new MessageEmbed()
                    .setTitle(`${user.user.tag}'s warns`)
                    .setDescription(
                        data.content.map(
                            (w, i) => 
                            `\`${i + 1}\` | Moderator : ${message.guild.members.cache.get(w.moderator).user.tag}\nReason : ${w.reason}`
                        )
                    )
                    .setColor("BLUE")
                message.channel.send({ embeds: [sembed] });

map is also undefined.

(I am using discordjs v13)

Models/warns:

const { Schema, model } = require('mongoose');

module.exports = model("warns", new Schema({
  userId: String,
  guildId: String,
  moderatorId: String,
  reason: String,
  timestamp: Number,
})
);

NOTE: This code is by using mongoose npm package (A database, pretty much like quick.db but better)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source