i am trying to extract uniq keys + all uniq values from an object of my mongo-documents.
lets say i have document structure like:
{
"userId": "1234",
"formFields": {
"field1": "value1",
"field2": "value2"
}
},
{
"userId": "1234",
"formFields": {
"field3": "value3",
"field1": "value1-edited"
}
},
{
"userId": "1234",
"formFields": {
"field3": "value3",
"field1": "value1-edited"
}
}
i want to aggregate all documents from user "1234" to get the distinct values of "formFields"
result should look something like this:
{
"_id": "1234",
"formFields": {
"field1": [
"value1",
"value1-edited"
],
"field2": [
"value2"
],
"field3": [
"field3"
],
"field4": [
"field4"
]
}
}
they keys in the formFields are dynamic. i tried arround with aggregate, and mapreduce but haven't found any working sample that can be used as a basis.
anyone can answer this?
THANKS
regards helmut