Greetings. MongoDB version 4.4
I need to create a view that will display information in the desired form from all available collections. But in some fields the data is stored as objects, I need to parse the short ones.
I am trying to do this within a single view, but I am having a problem getting one value from this field
db.createView( "testView", "pasport_data", [ { $project: { _id: 0, "collection": "pasport_data", "record_date": 1, "record_table_id": 1, "record_customer_id": 1, "record_questionnaire_id": 1, "record_user_id": 1, "record_type": 1, "column": {$objectToArray: "$record_edit_column"}, "record_value": 1, } }, { $unwind: "$column" }, { $project: { _id: 0, "collection": "pasport_data", "record_date": 1, "record_table_id": 1, "record_customer_id": 1, "record_questionnaire_id": 1, "record_user_id": 1, "record_type": 1, "column": "$column.k", "value_before": "$column.v", "value_after": "$record_value.$column.k", } } ] )
Pay attention to the last line “value_after”: “$record_value.$column.k”. The problem is, I don’t know how to get this value. If, instead, I specify the name of the parameter I need, for example “value_after”: “$record_value.serial_p”, it returns the desired value to me. Otherwise, the view works.
Help me please