Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "updateOperators"

Index

Functions

$inc

  • $inc(obj: any, inc: any): Promise<any>
  • Increment a value or subtract from a value.

    Example:

    let obj = {nested: {num: 1}};
    $inc(obj, {"nested.num": -1})
     .then((res) => console.log(res)) // {nested: {num: 0}}
     .catch();
    

    Parameters

    • obj: any
    • inc: any

    Returns Promise<any>

$mul

  • $mul(obj: any, mul: any): Promise<any>
  • Multiply a value

    Example:

    let obj = {nested: {num: 2}};
    $mul(obj, {"nested.num": 3})
     .then((res) => console.log(res)) // {nested: {num: 6}}
     .catch();
    

    Parameters

    • obj: any
    • mul: any

    Returns Promise<any>

$rename

  • $rename(obj: any, rename: any): Promise<any>
  • Rename a key

    Example:

    let obj = {nested: {v: "value"}};
    $rename(obj, {"nested.v": "key"})
     .then((res) => console.log(res)) // {nested: {key: "value"}}
     .catch();
    

    Parameters

    • obj: any
    • rename: any

    Returns Promise<any>

$set

  • $set(obj: any, set: any): Promise<any>
  • Replace a value

    Example:

    let obj = {nested: {layer1: {}}};
    $set(obj, {"nexted.layer1.newSet": "value"})
     .then((res) => console.log(res)) // {nested: {layer: {newSet: "value"}}}
     .catch();
    

    Parameters

    • obj: any
    • set: any

    Returns Promise<any>

$unset

  • $unset(obj: any, unset: any): Promise<any>
  • Remove key/value

    Example:

    let obj = {nested: {v: "value}};
    $unset(obj, {"nested.v": ""})
     .then((res) => console.log(res)) // {nested: {}}
     .catch();
    

    Parameters

    • obj: any
    • unset: any

    Returns Promise<any>

operate

  • operate(obj: any, is: any, value: any, type: string): any
  • Method used by all update operators except $rename to updated nested object values by use of a string - "nested.doc.key"

    Examples:

    let obj = {nested: {doc: {key: 1}}};
    
    operate(obj, "nested.doc.key", 2, "set");
    // obj = {nested: {doc: {key: 2}}}
    
    operate(obj, "nested.doc.key", -1, "inc");
    // obj = {nested: {doc: {key: 1}}}
    
    operate(obj, "nested.doc.key", 3, "mul");
    // obj = {nested: {doc: {key: 3}}}
    
    operate(obj, "nested.doc.key", "", "unset");
    // obj = {nested: {doc: {}}}
    

    Parameters

    • obj: any

      object to update

    • is: any

      "string.location"

    • value: any

      input

    • type: string

      operator type string

    Returns any

Generated using TypeDoc