Javascript TypeError:无法读取属性';标记名';在运行第一次运行的命令时返回的未定义值

Javascript TypeError:无法读取属性';标记名';在运行第一次运行的命令时返回的未定义值,javascript,node.js,mongoose,Javascript,Node.js,Mongoose,我正在编写一个discord bot(为了方便起见删除了大多数discord.js),它应该获取所有标记名(来自mongo数据库的数据)并显示出来。但是,在我第二次运行命令之后 const tagArgs = messasge.content.split(" ").slice(1); if (tagArgs[0] == 'all') { tags.find().lean() .then(docs => { for (amountoftag

我正在编写一个discord bot(为了方便起见删除了大多数discord.js),它应该获取所有标记名(来自mongo数据库的数据)并显示出来。但是,在我第二次运行命令之后

const tagArgs = messasge.content.split(" ").slice(1);
if (tagArgs[0] == 'all') {
    tags.find().lean()
    .then(docs => {
        for (amountoftags in docs) {
            let tagname = JSON.stringify(docs[num].tagName);
            tagname = tagname.substring(1,tagname.length-1)
            // code where tagname is used
            num = num + 1
        }
    
    })
我得到一个错误,声明

TypeError: Cannot read property 'tagName' of undefined
只有在我第二次运行它时才会发生这种情况—第一次运行得非常好。但是错误代码行

    let tagname = JSON.stringify(docs[num].tagName);
这意味着在第二次重新运行时,从mongo数据库获取的文档是不同的(即,不在列表中的对象中)。每当我进行故障排除时(我只记录控制台中
文档
的内容),它都会返回未定义。我哪里出了问题

我的猫鼬模式和模型:

const tagSchema = new mongoose.Schema ({
    tagName: String,
    tagContent: String
  });

const tags = new mongoose.model("Tags", tagSchema);
如果需要额外的上下文,请发表评论