Mongoose - Version Error: No matching document found for id

前端 未结 4 1854
眼角桃花
眼角桃花 2020-12-12 01:59

Context: I have a Post Mongoose model that contains a csv_files array field to store csv strings. I make a fetch API

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-12 02:11

    just to comment here what my problem apparently was.

    Error Message:

    message: 'No matching document found for id "5c86d3a15bbcb965d85d80d1" version 3', name: 'VersionError', version: 3

    My code:

    update: function (data) {
    
            var session = new Session(data);
            database.logging("INFO", "session-update", session.cid, session.order.orderNumber);
            return new Promise(function (resolve, reject) {
    
                session.save()
                    .then(savedSession => resolve(savedSession))
                    .catch(savedSessionError => reject(savedSessionError))
            });
    
        }
    

    My parameter 'data' was already a Mongoose object and I was creating a new one and trying to save() it. So like @dacopenhagen said, save() checks the version of the document and it's throwing an VersionError error.

    How I fixed it Just removing the creation of the Session() object. Removed this line

    var session = new Session(data);
    

    I hope this help.

提交回复
热议问题