The normal way for mongodb is to store data(unknown values) to arrays,
and keys to be metadata(the known schema)
The reasons for that is
1)unknown fields cannot be indexed
in your first approach if you want to index the comment_id,you can do it with
a multikey index,but in second how to make index on comment_id?
2)Dynamic embeded documents are not well supported
For example we cant do get($$k)/remove($$k)/add($$k,$$v) in a fast way.
(if key is a mongodb variable)
If we have constant keys,meaning that we know them at the time we send the
query(not keys in mongodb variables),we can use pipeline stage operators,or even
construct, query parts,but those are weird methods.
Query pattern
For a given blog post, return comments with ids in a given array (around 1000 per second)
Query patttern,first approach
1)find post
2)filter comments you need($filter on the comments map)
*if you have like 10 average it will be very fast
Query pattern,second approach
1)find post
2)how you get the comments?
you contruct on driver something like the bellow,and you send the query after?
{"$project" {comments.100 1
comments.20 1}
....
}
This is weird way
I cant be sure the first is always the best,but i think in mongodb,data should go
into arrays,and schema should go into keys.