Skip to content

Protect your documents in MongoDB (Mongoose) from concurrency error while saving.

Notifications You must be signed in to change notification settings

viniciusps2/mongoose-version-save

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongoose-version-save

Protect your documents in MongoDB (Mongoose) from concurrency error while saving.

This plugin adds a version check when saving the document, or subdocuments (array of objects within a schema). Allows concurrency when saving subdocuments, and throws error when there is a change in the same subdocument.

Install

npm i viniciusps2/mongoose-version-save

Using

const VersionSavePlugin = require('mongoose-version-save')

const ChildSchema = Schema({
  name: String,
  age: Number
})

ChildSchema.plugin(VersionSavePlugin)

const ParentSchema = Schema({
  name: String,
  age: Number,
  children: [Child],
})

ParentSchema.plugin(VersionSavePlugin)

const Parent = mongoose.model('Parent', ParentSchema)

And then create, delete, update, when someone else edit the document, it throws an error!

About

Protect your documents in MongoDB (Mongoose) from concurrency error while saving.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published