Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

__v versionKey gets deleted in document #45

Open
brianmtully opened this issue Nov 29, 2018 · 5 comments
Open

__v versionKey gets deleted in document #45

brianmtully opened this issue Nov 29, 2018 · 5 comments

Comments

@brianmtully
Copy link

brianmtully commented Nov 29, 2018

When using versionKeys in schema. The versionKey gets deleted when using this package.

`
function createHistoryDoc(d, operation) {
d.__v = undefined;

let historyDoc = {};
historyDoc['t'] = new Date();
historyDoc['o'] = operation;
historyDoc['d'] = d;

return historyDoc;

}
`
In the createHistoryDoc function, it sets the __v of the main document to undefined. This breaks updates on the document in the future. Big problem.

@nassor
Copy link
Owner

nassor commented Dec 19, 2018

Can you provide an example that breaks the updates?

@brianmtully
Copy link
Author

any call of findOneAndUpdate will run your 'pre' hook. Your hook sets the __v to undefined. After your hook runs the document is saved without the __v. So I believe an example would be calling a findOneAndUpdate and then after that is done, trying to update the document using save. The save pre hook does not have this issue of setting the __v to undefined.

@Ncifra
Copy link

Ncifra commented Dec 24, 2018

Hey @nassor, I think @brianmtully is referring to the original document's __v field. I am encountering the same problem where the original document's __v gets set to null (not undefined as above), but from the above I think that the history document's __v is set to undefined, not the original one.

@Mobasher-NetLinks
Copy link

Same issue occur when I use findOneAndUpdate, it removes __v value and change it to null in main collection documents, and break future update procedure. Please solve it, or let us know to find some other ways for history log.

@Ncifra
Copy link

Ncifra commented Jan 31, 2019

For now I did change the default mongoose version key name to another, instead of the default __v. It seems very strange why this one changes the __v key considering that it should be a post hook trigger, and the document must have been already saved, and the change shouldn't persist.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants