0
我不斷收到此錯誤:model.remove給modelname.remove(...)EXEC是不是一個函數
Mongoose: invoice.remove({ _id: 3 }, {})
TypeError: invoiceRecord.remove(...).exec is not a function
我試圖消除.exec但隨後它不會承認我的功能(ERR ,數據)
這裏是我的功能
var deleteInvoice =() => {
return new Promise((resolve, reject) => {
invoiceRecord.remove(
).exec(function (err, data) {
if (err) {
reject(new Error('deleteInvoice ERROR : ' + err));
return;
}
if (data.result.n == 0) {
reject({code:"INVOICE_NOTFOUND", err:"This invoice could not be found: " + invoiceRecord._id});
return;
}
resolve(data);
})
})};
我怎樣才能做到這一點,當我invoiceRecord
已經刪除所需要的數據?
這工作:
invoiceTable.remove (
{ _id: invoiceRecord._id }
,function(err, data) {
這不:
invoiceRecord.remove (
{ _id: invoiceRecord._id }
,function(err, data) {
我真的不明白爲什麼
感謝羅伯特 - 其實你鏈接貓鼬例子也說明'product.remove(函數(ERR,產品) {'除了這是行不通的,那是我第三次在一個星期內發現有瑕疵的例子,你用'invoiceRecord.remove()。then'完成的例子很好用! – torbenrudgaard
@torbenrudgaard我不知道爲什麼它不會工作;對我來說,它有回調和承諾,我想'invoiceRecord'是一個普通的Mongoose文檔嗎? – robertklep
是的,它是一個貓鼬模式無論如何你的解決方案工作:) – torbenrudgaard