mongostate
Version:
Data state machine. Support transaction in mongoose.
16 lines (12 loc) • 440 B
JavaScript
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const lockSchema = new Schema({
transaction: { type: Schema.ObjectId, required: true, index: true },
model: { type: String, required: true },
entity: { type: String, required: true },
}, {
read: 'primary',
});
lockSchema.index({ model: 1, entity: 1 }, { unique: true });
lockSchema.index({ entity: 1, model: 1, transaction: 1 });
module.exports = lockSchema;