Skip to content

Optimistic Concurrency Control (OCC)

Optimistic Concurrency Control (v1.11.0+)

  • Need to add “isConcurrencyControlField” for that version field in schema.
  • Update by ID, replace by ID, master save schema APIs will not allow update or replace without that version field and throw error if that version is mismatch with database value.
  • API Maker will allow update & replace from custom code like custom APIs or events or schedulers etc. and will not have any effect in code. If you want concurrency control in custom code you can use “skipConcurrencyControl: false” otherwise default value is true in custom code.

Sample code

import { ISchemaType, EType, ISchemaProperty, IPropertyValidation } from 'types';
import * as T from 'types';

let schema: ISchemaType = {
    _id: EType.objectId,
    name: EType.string,
    version: {
        __type: EType.number,
        conversions: {
            conversionFun: () => {
                return new Date().getTime();
            }
        },
        isConcurrencyControlField: true, // 👈
    }
};

module.exports = { schema };