db.test1.update(
{
"filter_field": 1,
},
[
{$set: {
"target_field": "$source_field"
}}
]
);
db.test1.update(
{
"filter_field": 1,
},
[
{$set: {
"target_field": "$source_field"
}}
]
);
{$cond: {
if: {$eq: [ {$ifNull: ["$FIELD_NAME", null]}, null ]},
then: NumberInt(0),
else: NumberInt(1)
}},
"highlights_field_name": {
"type": "array",
"items": {
"type": "object",
"title": "highlights_title",
"properties": {
"path": {
"type": "string"
},
"score": {
"type": "number"
},
"texts": {
"type": "array",
"items": {
"type": "object",
"title": "piece_texts",
"properties": {
"value": {
"type": "string"
},
"type": {
"type": "string"
}
}
}
}
}
}
}
"field_name": {
"type": "array",
"items": {
"type": "string"
}
}
This is the specification for such field:
"field_name": {
"type": "array",
"items": {
"type": "integer",
"type": "integer"
}
}
db.MAIN_COLLECTION_NAME.aggregate([
{$match: {
"ANY_FIELD_0": "ANY_VALUE",
}},
{$lookup: {
from: "COLLECTION_NAME_TO_LOOKUP_FROM",
let: {
"FIELD_ALIAS_1": "$MAIN_COLLECTION_ANY_FIELD_1",
"FIELD_ALIAS_2": "$MAIN_COLLECTION_ANY_FIELD_2",
},
pipeline: [
{$match: {
$expr: {$eq: ["$ANY_FIELD_1", "$$FIELD_ALIAS_1"]},
$expr: {$eq: ["$ANY_FIELD_2", "$$FIELD_ALIAS_2"]},
}},
],
as: "LOOKUP_RESULTS_FIELD_ALIAS"
}},
]);
select
t.*,
j.`single_value`
from
database_name.`table_name` as t
inner join
json_table(
json_array(t.`csv_source_field_name`)
'$[*]'
columns (
`single_value` varchar(50)
path '$'
)
) as j
;
select
table_alias.*
-- See how the field was split into several columns
-- (index, value, etc)
, flattened_alias.*
-- How to extract only the value
, TRIM(flattened_alias.value::string) as "flattened_value"
from
"database_name"."schema_name"."table_name" as table_alias
cross join
lateral flatten(
input => split(
table_alias."csv_source_field_name",
';' -- Separator
)
) as flattened_alias
;
for file in *.FILE_EXTENSION_IF_ANY
do
mv "$file" "STRING-TO-APPEND-${file}"
done
_(your_array).sortBy(
function(elem) {
return [elem.field_to_sort_by_1, elem.field_to_sort_by_1];
}
);
const string_here = "asdf";
const file = new File(
[string_here],
"file_name.xml",
{type: "application/xml"}
);
PS. Then this can be treated as an input file to, for example, upload to an S3 bucket.
db.users.aggregate([
{$project:{
"field_count": {$size: {$objectToArray:"$$ROOT"}}
}},
{$group:{
"_id": {field_count: "$field_count"},
"document_count": {$sum: NumberInt(1)},
}},
{$project:{
"field_count": "$_id.field_count"
, "document_count": 1
, "_id": 0
}},
{$sort: {
"field_count": -1
}}
]);
PS. In other words, how many documents exist for each field count (e.g. "78 documents have 5 fields").
db.COLLECTION_NAME.aggregate([
{$project:{
"arr": {$objectToArray:"$$ROOT"},
}},
{$unwind: "$arr"},
{$project: {
"_id": 0,
"k": "$arr.k",
}},
{$group: {
"_id": { "k": "$k" },
"f": {$sum: NumberInt(1)},
}},
{$project: {
"_id": 0,
"k": "$_id.k",
"f": 1,
}},
{$sort: {
"f": -1,
"k": 1,
}},
]);
db.COLLECTION_NAME.aggregate([
{$unwind: {
"path": "$FIELD_NAME",
"preserveNullAndEmptyArrays": true
}}
]);