$push
Reference group: Array update operators
What it does
Appends a value; $each, $sort, $slice, and $position can customize behavior.
Syntax
{$push: { array: value }}
Use case
Append events or maintain bounded recent items.
$push: practical example
db.posts.updateOne({ _id: postId }, { $push: { tags: "mongodb" } })💡 Explanation
Appends a value;
$each, $sort, $slice, and $position can customize behavior.
When to use it
Append events or maintain bounded recent items.Key Takeaways
- Appends a value;
$each,$sort,$slice, and$positioncan customize behavior. - Typical use: Append events or maintain bounded recent items.