2017-09-18 25 views
0

私はマングーススキーマを持っています。元のスキーマに "imagens"フィールドを追加しました。マングースバージョンのエラーIDが一致するドキュメントが見つかりません

フィールドが追加さは、次のとおりです。私は「imagens」フィールドを記入し、コレクションを更新しようとすると

imagens:[{title:{type: String},savedAs:{type: String},file:{type: String}, thumb:{type: String}}], 

は今、私は次のエラーを取得します。 そして、もし私が 'item.imagens = imgs'という行を取り除くと、エラーはなくなります。

私は間違っていますか?この問題にいくつかの修正がありますか?

//エラー

 {"data":{"message":"No matching document found for id \"5909caeed32a453b537f7966\"", 
"name":"VersionError"}, "status":500, 
     "config":{"method":"POST","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback", 
    "url":"/uploads", 
    "data":{"file":{"$ngfBlobUrl": 
    "blob:http://localhost/9c4b0449-1ddd-4e39-ab44-f2e9a21bfd82","$ngfWidth":450,"$ngfHeight":321, 
    "upload":{},"progress":100},"pacID":"5909caeed32a453b537f7966"},"_isDigested":true, 
    "_chunkSize":null,"headers":{"Accept":"application/json, text/plain, */*"},"_deferred":{"promise":"..."},"cached":false},"statusText":"Internal Server Error"} 

//私のルータで

Cliente.findById(pac_id, function (err, item) { 
            if (err) { 
             return res.status(500).send(err); 
            } else { 
             item.imagens=imgs 
            } 
            item.save(function (err, data) { 
             if (err) { 
              return res.status(500).send(err) 
             } 
             if (answers.results.length){ 
              answers.message='Some files was not uploaded' 
             } else { 
              answers.message='Files were uploaded' 
             } 
             res.send(answers) 
            }) 
            }) 

//モデル

const mongoose=require('mongoose'); 
const clientesSchema = new mongoose.Schema({ 
    id: {type: Number, unique:true}, 
    nome: {type: String, unique:true}, 
    ativo: {type: Boolean}, 
    ... 
    ... 
    foto: { data: Buffer, contentType: String }, 
    imagens:[{title:{type: String},savedAs:{type: String},file:{type: String}, thumb:{type: String}}], 
    created_at:{type:Date,default:Date.now}, 
    altered_at:{type:Date,default:Date.now} 
}); 


module.exports = mongoose.model('Cliente', clientesSchema,'clientes'); 

答えて

1

は、バージョンの競合を解決します文書のバージョンを削除します。 はその後、マングースがあなたが保存できるようになります。

delete item.__v 
item.save(...) 
+0

はあなたのジェレミーありがとう、私はそれを試してみましたが、問題が解決しません。なぜなら、私が "imagens"配列に1つのイメージしか入れないと、問題は現れないからです。フィールド配列に2つ以上のイメージアイテムを配置すると、問題が表示されます –

+1

ありがとう、それでした。私が間違えました。 –

関連する問題