mongo /僧侣 - 没有解雇promise.done?

时间:2015-08-28 06:27:27

标签: javascript mongodb callback promise monk

我正在使用mongo / monk尝试减少一些CB的丑陋,但它似乎会产生更多不寻常的调试问题("现在你有两个问题")。

基于: https://gentlenode.com/journal/node-4-monk-cheatsheet/45

我有一个例程来清除一个集合并插入一些数据, 但是on.complete或on.success不会触发

    QuizPlugin.collection.remove({}, function(err, doc) {
        Clog.log("QP", "removed"); // get this
        var raw = FileReader.readDataFile(jsonfile);
        var that = this;
        raw.records.map(item => {
            var p = QuizPlugin.collection.insert(item.fields);
            console.log("p.type", p.type);
            p.on("success", function(doc) {
                console.log("done", doc) // never
            });
            p.on("complete", function(doc) {
                console.log("done", doc) // not this one either
            });
            p.on("error", function() {
                console.log("error")  // or this ever show up
            });

            // this method also doesn't emit anything
            // QuizPlugin.collection.insert(item.fields, function(err, doc) {
            //  console.log("inserted")
            // });
            // Clog.log("inserted:", item.fields.question);
        })

    })

内部on("success")还没有其他原因被解雇吗? 如果斯巴达,文档看起来很清楚 https://github.com/Automattic/monk#promises

0 个答案:

没有答案