$push
Add new elements to an array field in the specified column. The $push method appends one or more values to an existing array without replacing the entire array. For example, if the current value of a column is ["apple", "banana"] and you use $push: "cherry" or $push: $each: ["cherry"], the updated array becomes ["apple", "banana", "cherry"]. This is useful for maintaining and expanding lists within database records.
await Member.$update({
$where: {
age: {
$eq: 16
}
},
$update: {
$push: {
badges: 'CEO'
}
}
});
await Member.$update({
$where: {
age: {
$eq: 16
}
},
$update: {
$push: {
badges: {
$each: ['CEO','VIP','SEO','Owner'],
$position: 1,
$sort: -1
}
}
}
});
Last updated