Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Predefined Update Options Quick Reference

Arrays

$push

Adds an element to the end of an array.

{
    $push: { tags: "designer" }
}

Input:

{
    tags: ["developer"]
}

Output:

{
    tags: ["developer", "designer"]
}

$pushset

Adds an element to the end of an array and removes duplicates.

{
    $pushset: { tags: "designer" }
}

Input:

{
    tags: ["developer", "designer", "developer"]
}

Output:

{
    tags: ["developer", "designer"]
}

$pull

Removes a specific element from an array.

{
    $pull: { tags: "developer" }
}

Input:

{
    tags: ["developer", "designer"]
}

Output:

{
    tags: ["designer"]
}

$pullall

Removes all occurrences of specified elements from an array.

{
    $pullall: { tags: ["developer", "designer"] }
}

Input:

{
    tags: ["developer", "designer", "manager"]
}

Output:

{
    tags: ["manager"]
}

Numbers

$inc

Increments a numeric value by a given amount.

{
    $inc: { counter: 1 }
}

Input:

{
    counter: 5
}

Output:

{
    counter: 6
}

$dec

Decrements a numeric value by a given amount.

{
    $dec: { counter: 1 }
}

Input:

{
    counter: 5
}

Output:

{
    counter: 4
}

Objects

$merge

Merges a nested object, adding or updating properties.

{
    $merge: { settings: { theme: "dark" } }
}

Input:

{
    settings: { theme: "light", language: "en" }
}

Output:

{
    settings: { theme: "dark", language: "en" }
}

Others

$unset

Removes a specified key from an object.

{
    $unset: { age: true }
}

Input:

{
    name: "John",
    age: 30
}

Output:

{
    name: "John"
}

$rename

Renames a key in an object.

{
    $rename: { firstName: "name" }
}

Input:

{
    firstName: "John",
    lastName: "Doe"
}

Output:

{
    name: "John",
    lastName: "Doe"
}