Context
Example JSON content (fetched with Mongoose)
[
{
"name": "user1",
"blogs": [
{
"title": "blog1",
"created": "01-01-2020"
},
{
"title": "blog2",
"created": "01-01-2020"
}
]
},
{
"name": "user2",
"blogs": [
{
"title": "blog3",
"created": "01-01-2020"
},
{
"title": "blog4",
"created": "01-01-2020"
}
]
}
]
Problem
I'm trying to show a list of all blog posts, sorted by the creation date of the post and show the user that created it.
Injecting the above object in Pug and performing a foreach will group all performances by the user and makes it impossible to sort on the creation date of all performances (in thisobject form).
My solution would be the object to the following:
Example JSON, mapping each blog entry to a user
[
{
"name": "user1",
"blog": {
"title": "blog1",
"created": "01-01-2020"
}
},
{
"name": "user1",
"blog": {
"title": "blog2",
"created": "01-01-2020"
}
},
{
"name": "user2",
"blog": {
"title": "blog3",
"created": "01-01-2020"
}
},
{
"name": "user2",
"blog": {
"title": "blog4",
"created": "01-01-2020"
}
}
]
This object form could make it possible to still display the data of the user with each blog entry and sort on the creation date of the performance.
I'm trying to achieve the latter, but I haven't found a clean way of doing it without foreaching or mapping.
Note
This problem could easily solved by defining a relationship and resolving the keys, but I'm explicitly trying to solve this problem with NoSQL. Consequently, there is no reference of the user in the blog entity.
How would you solve this and what is the characteristic name of this particular operation?