KeyTakeAways About MongoDB $push Operator
- The $push operator in MongoDB is used append a new value into the array in the specific index.
- If the specified field in the $push operator is not present in the document, then this operator will add the array field with the value as its items.
- You can use this operator with methods like update(), findAndModify(), etc., according to your requirements.
- The $push operator inserts items at the end of the array.
- If the specified field in the $push operator is not an array, then this operation will fail.
- If the value of the $push the operator is an array, then this operator will append the whole array as a single element. And if you want to add each item of the value separately, then you can use $each modifier with $push the operator.
MongoDB $push Operator
MongoDB $push operator appends a value to the already existing array within a document.
Contact Us