MongoDB查询对象数组

时间:2017-09-01 06:27:24

标签: mongodb mongodb-query

我有以下数据

> 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" : ""
                }
        ]
}

我正在尝试编写查询以获取如下所示的输出,我正在尝试使用unwind,但这会产生错误的结果

{  
   "_id":ObjectId("59a7ead6d122a2332e1eb164"),
   "name":"Jack",
   "status":"VERIFIED",
   "patient":"vijay jha",
   "notes":"",
   "surgeon":"Thomas"
}

0 个答案:

没有答案