In MongoDB, the $concatArrays
aggregation pipeline operator concatenates two or more arrays and returns the concatenated array.
Tag: arrays
Import CSV Data as an Array in MongoDB using mongoimport
MongoDB’s import utility – mongoimport
– introduced a new parameter that allows you to import CSV data as an array.
The --useArrayIndexFields
parameter interprets natural numbers in fields as array indexes when importing CSV or TSV files.
Insert a Value at a Specific Position in an Array in MongoDB
In MongoDB, you can use the $push
operator to append a value to an array.
This operator can be used with various modifiers, one of which is the $position
modifier. The $position
modifier allows you to specify the position within the array that you want to insert the new value.
MongoDB $arrayElemAt
In MongoDB, the $arrayElemAt
aggregation pipeline operator returns the element at the specified array index.
It accepts two arguments;
- The array
- The index of the element you want to retrieve
How the arrayFilters Parameter Works in MongoDB
In MongoDB, when you update documents that contain arrays, you have the option of using the arrayFilters
parameter.
The arrayFilters
parameter allows you to specify an array of filter documents that determine which array elements to modify.
In the update document, use the $[<identifier>]
filtered positional operator, which identifies the array elements that match the arrayFilters
conditions for the update operation.
JSON_ARRAY_INSERT() – Insert Values into a JSON Array in MySQL
In MySQL, the JSON_ARRAY_INSERT()
function is used to insert a new value into an array.
You provide the JSON document as the first argument, followed by the path to insert into, followed by the value to insert.
JSON_ARRAY_APPEND() – Append Values to a JSON Array in MySQL
When using JSON documents with MySQL, we can use the JSON_ARRAY_APPEND()
function to append new values to an array.
The way it works is, you provide the JSON document as the first argument, then follow that up with the path to append to, followed by the value to append.
In MySQL 5.7, this function was called JSON_APPEND()
but that name is no longer supported.
JSON_ARRAY() – Create a JSON Array from a List of Values in MySQL
In MySQL, you can use the JSON_ARRAY()
function to create a JSON array from a list of values. You provide each value as a separate argument. Each argument becomes a separate element of the array.
The function also accepts an empty list (i.e. you provide no arguments). In this case, you’ll get an empty array.
JSON_ARRAYAGG() – Create a JSON Array from the Rows of a Query in MySQL
Among the many MySQLÂ aggregate functions is one called JSON_ARRAYAGG()
. This function enables you to aggregate a result set as a single JSON array. Each row of the result set ends up as a single element in the array.
The order of the elements in the array is undefined.