I have a Yii2 mongodb's collection that looks like this:
{
"_id" : "123",
"books" : [
{
"author" : "John",
"title" : "The Book"
},
{
"author" : "Smith",
"title" : "Something!"
}
]
}
{
"_id" : "321",
"books" : [
{
"author" : "John",
"title" : "The Book"
}
]
}
...
And I want to get an array of all books (an array of arrays basically):
[
{
"author" : "John",
"title" : "The Book"
},
{
"author" : "Smith",
"title" : "Something!"
},
{
"author" : "John",
"title" : "The Book"
}
...
]
I saw answers to close questions, but they all achieve something a bit different.
Also tried $collection->distinct('books', [], [])
and it worked, but it removed duplicates which is unacceptable.