I have data like below
> db.user.find().pretty().limit(1);
{
"_id" : ObjectId("59a7ead6d122a2332e1eb164"),
"name" : "Jack",
"status" : "VERIFIED",
"attributes" : [
{
"value" : "vijay jha",
"name" : "patient",
"key1" : "",
"key2" : "",
"key3" : ""
},
{
"value" : "",
"name" : "notes",
"key1" : "",
"key2" : "",
"key3" : ""
},
{
"value" : "Thomas",
"name" : "surgeon",
"key1" : "",
"key2" : "",
"key3" : ""
}
]
}
I am trying to write query to get output like below , I am trying to use unwind but that is producing incorrect result
{
"_id":ObjectId("59a7ead6d122a2332e1eb164"),
"name":"Jack",
"status":"VERIFIED",
"patient":"vijay jha",
"notes":"",
"surgeon":"Thomas"
}
$arrayToObjectis not supported? Go back and read the nice answer again."errmsg" : "'newRoot' expression must evaluate to an object, but resulting value was: null. Type of resulting value: 'null'. Input document: {_id: 59a7ead6d122a2332e1eb166}",attributesarray for each document. I may have lot of documents without this array.$matchand use$exists. Now say thankyou.