2017-10-03 14 views
0

私はmongooseとmongoose-gridfsモジュールを使用していますが、エラーを修正する方法を理解できません。 は簡単に私のデシベルにファイルを追加し、それを読むことができます:Gridfsファイルの削除エラー

router.get('/:id', (req, res)=> { 
    if (gridfs == null) { 
     gridfs = require("mongoose-gridfs")({ 
      collection: 'attachments', 
      model: 'Files' 
     }); 
     Attachment = gridfs.model; 
    } 
    let stream = Attachment.readById(req.params["id"]); 
} 

しかし、私は削除ルートで同じ方法を使用しています:

router.delete('/:id', (req, res)=> { 
    if (gridfs == null) { 
     gridfs = require("mongoose-gridfs")({ 
      collection: 'attachments', 
      model: 'Files' 
     }); 
     Attachment = gridfs.model; 
    } 
    Attachment.unlinkById(req.params["id"], (err) => { 
    }); 
} 

それは私にエラーTypeError例外を投げるです:プロパティを読み取ることができません "ヌルのリンクを解除する。 何が間違っていますか?以下に示すように、変数を「gridfs」初期化すると「マングース-gridfs」を必要とするが、あなたのマングースの接続に渡してみてください

答えて

0

//instantiate mongoose-gridfs 
var gridfs = require('mongoose-gridfs')({ 
    collection:'attachments', 
    model:'Attachment', 
    mongooseConnection: connection 
}); 

をまたreq.paramsの値をログに記録しようとしている価値があるかもしれません[ "id"]あなたがそこにIDを持っていることを確認してください。以下に示すように

代わりunlinkByIdのリンク解除方法を試してください。

Attachment.unlink(<objectid>, function(error, unlinkedAttachment){ 
    ... 
}); 
関連する問題