【发布时间】:2016-09-18 09:28:06
【问题描述】:
谁能告诉我为什么这个承诺设置不起作用。它应该删除文档然后添加它然后找到它然后控制台它。它不是在安慰数据。
var Comp = require("./models/company.js");
var arr = [
{name : "comp1",industry : "industry1", ranking: 20},
{name : "comp2",industry : "industry2", ranking: 5},
{name : "comp3",industry : "industry3", ranking: 10}
]
var output = {};
var promise = Comp.find({}).exec()
promise.then(function(res){
console.log("removed")
return Comp.remove({}).exec()
})
.then(function(){
return Comp.create(arr).exec()
})
.then(function(data){
return Comp.find({}).exec();
})
.then(function(data){
console.log(data)
})
编辑::
发现错误
[TypeError: Comp.create(...).exec is not a function]
【问题讨论】:
标签: javascript node.js mongodb mongoose promise