ReferenceError: list is not defined with mongoose

ReferenceError: list is not defined with mongoose

我在尝试使用以下方法写入数据库时​​遇到一个奇怪的问题:

app.post('/l/create', function(req, res) {
    var text = req.body.text;
    console.log('Inside create');
    console.log(text);

    var listObj = {
        index: 0,
        name: text,
        cards: []
    };

    console.dir(listObj);

    DB.ListTable.create(listObj,
        function(err) {
            if (err) res.send(err);

            getSnippets(res);
        }
    );
});

这是我收到的错误消息:

C:\NodeApps\myapp\node_modules\mongoose\lib\document.js:1116
    if (list.path.indexOf(lastPath) !== 0) {
        ^
ReferenceError: list is not defined
at C:\NodeApps\myapp\node_modules\mongoose\lib\document.js:1116:9
    at Array.forEach (native)
    at model.Document.$__dirty 
    (C:\NodeApps\myapp\node_modules\mongoose\lib\document.js:1115:7)

我 运行 在 table 上删除时没有得到这个。

我可能是造成这种情况的原因。请帮忙

我整天都在为这个问题苦思冥想。只需删除所有 node_modules 并执行 npm install 即可解决此问题。

我真的不明白这是怎么发生的,但我的应用程序崩溃后的最后一次更改是安装 nodemon

您正在使用 NODE 包 (nodemon) 特定语法迭代 arraylist 并且您的计算机上未安装节点包。

您还有另一种选择,可以使用 javascript 遍历 arrayList 的方式,例如:

            for (var x in summary){
                if (summary.hasOwnProperty(x)){
                console.log("-  array--"+x)
                }