I am wondering what is exactly the difference in the following scenario. We have Posts
which are created by users and therefore consist of a field userId
in addition to the field postContent
.
I can now think of two possible solutions:
- Having a simple top-level collection
Posts
where each Post is a document and a separateUsers
top-level collection where each user is represented by a document.
- Having a
Users
top-level collection and a subcollectionUserPosts
under each user document.
Two possible queries:
Give me all posts of user xyd. Could be done with solution 1 by asking for all documents in the collection
Posts
whereuserId == 'xyd'
. Could also be done with solution 2 by asking 'get all documents under subcollection of user-doc with the id 'xyd''Give me all posts with the word 'Cats' in them. Shouldn't this also be possible with both solutions? Solution one is a basic query and solution 2 by just making a groupcollection query over the field where
postContent
>= 'Cats'?
Do I forget anything? Or are these two solutions both valid? If both are valid, in which scenario I just described is correct?