MongoDB flatten a deep nested document

In notebook:
Work Notes
Created at:
2015-12-16
Updated:
2015-12-16
Tags:
with the aggregate ​unwind​ command
  { $unwind: "$notebooks" },
{ $unwind: "$notebooks.notes"},
{ $project: {
    anote: "$notebooks.notes", 
    _id: 0
}}
the original collection look like this:
  [
    {
        "name": "workshops",
        "notebooks": [
            {
                "name": "FEM1",
                "notes": [
                    {
                        "name": "intro1",
                        "contents": "intro description"
                    },
                    {
                        "name": "exercise",
                        "contents": "exercise solution"
                    }
                ]
            },
            {
                "name": "FEM2",
                "notes": [
                    {
                        "name": "start",
                        "contents": "start of the course"
                    },
                    {
                        "name": "solution",
                        "contents": "description of the soluion"
                    }
                ]
            }
        ]
    },
    {
        "name": "readinglist",
        "notebooks": [
            {
                "name": "articlenotes",
                "notes": [
                    {
                        "name": "Objectcreate",
                        "contents": "object create vs new"
                    },
                    {
                        "name": "blissfulljs",
                        "contents": "blissfull js library desc"
                    }
                ]
            }
        ]
    }
]